nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.7k stars 29.1k forks source link

warning about icu-small WHEN compile with gnu++23 #54067

Open navegador5 opened 1 month ago

navegador5 commented 1 month ago

Version

Node.js v22.4.1.

Platform

Linux dev 5.15.0-117-generic #127-Ubuntu SMP Fri Jul 5 20:13:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

I just change the std=gnu++xxxx IN cc_flags to std=gnu++23. others same as default then:

$ ./configure
$ make -j12
------------
  ../deps/icu-small/source/common/unicode/char16ptr.h:222:53: warning: dangling pointer to an unnamed temporary may be used [-Wdangling-pointer=]
  222 | ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) : p_(p) {}

How often does it reproduce? Is there a required condition?

always.

What is the expected behavior? Why is that the expected behavior?

no warning

What do you see instead?

../deps/icu-small/source/common/unicode/char16ptr.h:222:53: warning: dangling pointer to an unnamed temporary may be used [-Wdangling-pointer=]
  222 | ConstChar16Ptr::ConstChar16Ptr(const char16_t *p) : p_(p) {}

Additional information

No response

navegador5 commented 1 month ago

FYI : when I copy paste the original-code from char16ptr.h out AND then compile just-it, every thing is OK( no warning ):

class  ConstChar16Ptr final {
    public:
      inline ConstChar16Ptr(const char16_t *p) :p_(p) {};
      inline const char16_t *get() const { return p_; };
      inline ~ConstChar16Ptr(){
        //asm volatile("" : : "rm"(p_) : "memory");
      };
  private:
    ConstChar16Ptr() = delete;
    template<typename T> static const char16_t *cast(const T *t) {
        //asm volatile("" : : "rm"(t) : "memory");
        return reinterpret_cast<const char16_t *>(t);
    }  
    const char16_t *p_;
};

int main()  {
   {
      mcr_shtnm(decltype(u"abc")); //const char16_t(&)[4]
      auto* p0 = reinterpret_cast<char*>(const_cast<char16_t*>(ConstChar16Ptr{u"abc"}.get()));
      auto* p1 = (char*)(const_cast<char16_t*>(ConstChar16Ptr{u"abc"}.get()));
      auto* p2 = (char*)(ConstChar16Ptr{u"abc"}.get());
      auto* p3 = reinterpret_cast<const char*>(ConstChar16Ptr{u"abc"}.get());
      mcr_shtnm(decltype(p0));   //char*
      mcr_shtnm(decltype(p1));   //char*
      mcr_shtnm(decltype(p2));   //char*
      mcr_shtnm(decltype(p3));   //const char *
   }
   std::cout << "------------------------" << std::endl;
   {
      auto* P  = u"abc";  
      auto* p0 = reinterpret_cast<char*>(const_cast<char16_t*>(ConstChar16Ptr{P}.get()));
      auto* p1 = (char*)(const_cast<char16_t*>(ConstChar16Ptr{P}.get()));
      auto* p2 = (char*)(ConstChar16Ptr{P}.get());
      auto* p3 = reinterpret_cast<const char*>(ConstChar16Ptr{P}.get());
      mcr_shtnm(decltype(P));  //const char16_t*
      mcr_shtnm(decltype(p0)); //char*
      mcr_shtnm(decltype(p1)); //char*
      mcr_shtnm(decltype(p2)); //char*
      mcr_shtnm(decltype(p3)); //const char *
   }
}

but when i compile it with all the code in nodejs, the warning appeared(boring...)