[Bug c++/98105] constexpr and unnamed namespace yields relocation R_X86_64_PC32 against undefined symbol ... can not be used when making a shared object; recompile with -fPIC

2023-06-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98105

--- Comment #3 from Andrew Pinski  ---
Reduced:
```
void f(const int&);

namespace {
  struct myFactory
  {
static constexpr int s_sList = 1;
  };
}
//constexpr int myFactory::s_sList;
void sdi_register_model()
{
  f(myFactory::s_sList);
}
```

If we uncomment the definition, it works.

I think this is correct behavior, just we should produce a better error message
of not have the definition and only the declaration here.

[Bug c++/98105] constexpr and unnamed namespace yields relocation R_X86_64_PC32 against undefined symbol ... can not be used when making a shared object; recompile with -fPIC

2020-12-03 Thread peter_foelsche at mentor dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98105

--- Comment #2 from Peter Foelsche  ---
sorry -- adding a definition outside of class for the variable solves the
problem!

[Bug c++/98105] constexpr and unnamed namespace yields relocation R_X86_64_PC32 against undefined symbol ... can not be used when making a shared object; recompile with -fPIC

2020-12-02 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98105

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Keywords||wrong-code
 Ever confirmed|0   |1
   Last reconfirmed||2020-12-03

--- Comment #1 from Richard Biener  ---
So somehow we are not emitting

namespace
{

class myFactory:public factory
{   public:

   static constexpr LIST s_sList = {
{1.0, 0}
};

...
};
}

but I'm not literate enough in C++ to tell if there's a definition missing.

It works with -std=c++17 but not with -std=c++11 or -std=c++14