[Bug c++/54483] undefined reference to static constexpr in .so
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 --- Comment #13 from Thiago Macieira --- (In reply to Andrew Pinski from comment #11) > You still need: > constexpr float A::val; In C++11 mode, yes. C++17 made all static constexpr data members implicitly inline, which change the situation. Inline variables ought to be emitted on use and merged at runtime. This explanation does not change the resolution of this bug report. But if you can update your code to use -std=c++17, gnu++17 or later, then the problem goes away.
[Bug c++/54483] undefined reference to static constexpr in .so
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 Andrew Pinski changed: What|Removed |Added CC||thiago at kde dot org --- Comment #12 from Andrew Pinski --- *** Bug 113465 has been marked as a duplicate of this bug. ***
[Bug c++/54483] undefined reference to static constexpr in .so
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 Andrew Pinski changed: What|Removed |Added Status|REOPENED|RESOLVED Resolution|--- |INVALID --- Comment #11 from Andrew Pinski --- (In reply to Mitsuru Kariya from comment #9) > (In reply to Juisoo from comment #8) > > However, if I add another data member which is initialized with val by > > default, I still get the "undefined reference" error, see second attachment. > > The second testcase is reduced like below. > > == testcase == > struct A { > static constexpr float val = 0.08; > A(const float& = val) {} > }; > > int main() > { > A{}; > } > == testcase == > cf. http://melpon.org/wandbox/permlink/ZCbNwLlPQakWjluY You still need: constexpr float A::val;
[Bug c++/54483] undefined reference to static constexpr in .so
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 Denis Sherstennikov changed: What|Removed |Added CC||ddsherstennikov at ya dot ru --- Comment #10 from Denis Sherstennikov --- Still an issue at gcc 5.3.0.
[Bug c++/54483] undefined reference to static constexpr in .so
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 Mitsuru Kariya changed: What|Removed |Added CC||kariya_mitsuru at hotmail dot com --- Comment #9 from Mitsuru Kariya --- (In reply to Juisoo from comment #8) > However, if I add another data member which is initialized with val by > default, I still get the "undefined reference" error, see second attachment. The second testcase is reduced like below. == testcase == struct A { static constexpr float val = 0.08; A(const float& = val) {} }; int main() { A{}; } == testcase == cf. http://melpon.org/wandbox/permlink/ZCbNwLlPQakWjluY I think that the testcase is ill-formed because the A::val is odr-used. When A's ctor is called with no argument, 1) The lvalue-to-rvalue conversion is not applied to A::val. (Since the ctor's parameter is a reference type.) 2) A::val is not a discarded-value expression. On the other hand, A::val is not odr-used in the first testcase. (Since the builtin unary - operator requires that its operand is a prvalue.) So, I think that this pr is fixed. (But I don't know whether this pr can be closed since I cannot find a test.)
[Bug c++/54483] undefined reference to static constexpr in .so
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 --- Comment #8 from Juisoo --- The described case seems to work in GCC 4.9.2 with the attached files and g++ -c -fpic testicle.cc -std=c++11 g++ -shared -o libtesticle.so testicle.o g++ -L/home/usack/entwicklung/tetris -Wall -o testicles main.cc -ltesticle -std=c++11 However, if I add another data member which is initialized with val by default, I still get the "undefined reference" error, see second attachment.
[Bug c++/54483] undefined reference to static constexpr in .so
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 --- Comment #7 from Juisoo --- Created attachment 34148 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34148&action=edit second test case
[Bug c++/54483] undefined reference to static constexpr in .so
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 Juisoo changed: What|Removed |Added CC||usack at math dot fu-berlin.de --- Comment #6 from Juisoo --- Created attachment 34147 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34147&action=edit Files for testcase of initial post
[Bug c++/54483] undefined reference to static constexpr in .so
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 --- Comment #5 from Jonathan Wakely 2012-09-07 08:30:36 UTC --- (In reply to comment #3) > (In reply to comment #1) > > This is invalid as per [class.static.data]/3 : > > On C++11 level it should be valid http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#712 is post-C++11 but as a DR we should implement it for all values of -std
[Bug c++/54483] undefined reference to static constexpr in .so
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 Paolo Carlini changed: What|Removed |Added Status|RESOLVED|REOPENED Last reconfirmed||2012-09-05 Resolution|INVALID | Ever Confirmed|0 |1 --- Comment #4 from Paolo Carlini 2012-09-05 11:21:06 UTC --- Let's reopen this, then.
[Bug c++/54483] undefined reference to static constexpr in .so
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 --- Comment #3 from Daniel Krügler 2012-09-05 11:12:13 UTC --- (In reply to comment #1) > This is invalid as per [class.static.data]/3 : On C++11 level it should be valid, because odr-usage does not happen here according to [basic.def.odr] p3: "A variable x whose name appears as a potentially-evaluated expression ex is odr-used unless x is an object that satisfies the requirements for appearing in a constant expression (5.19) and ex is an element of the set of potential results of an expression e, where either the lvalue-to-rvalue conversion (4.1) is applied to e, or e is a discarded-value expression (Clause 5)."
[Bug c++/54483] undefined reference to static constexpr in .so
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 Richard Guenther changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||INVALID --- Comment #2 from Richard Guenther 2012-09-05 09:21:42 UTC --- .
[Bug c++/54483] undefined reference to static constexpr in .so
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483 Jakub Jelinek changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek 2012-09-05 07:49:57 UTC --- This is invalid as per [class.static.data]/3 : "A static data member of literal type can be declared in the class definition with the constexpr specifier; if so, its declaration shall specify a brace-or-equal-initializer in which every initializer-clause that is an assignment-expression is a constant expression. [ Note: In both these cases, the member may appear in constant expressions. — end note ] The member shall still be defined in a namespace scope if it is odr-used (3.2) in the program and the namespace scope definition shall not contain an initializer."