public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54483] New: undefined reference to static constexpr in .so
@ 2012-09-04 18:31 baliga at gmail dot com
  2012-09-05  7:50 ` [Bug c++/54483] " jakub at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: baliga at gmail dot com @ 2012-09-04 18:31 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

             Bug #: 54483
           Summary: undefined reference to static constexpr in .so
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: baliga@gmail.com


In a.hh 
---------

class A {
  static constexpr float val = 0.08;

  public:
   bool foo(const float v);
};


In a.cc
--------

bool A::foo(const float v) {
  return (v < -val);
}

Created a libfoo.so from the above code and linked this .so with another
executable using A::foo(const float) method.

Creating an executable result in "undefined reference to A::val"

If I replace val with -0.08 and change foo method with return (v < val), val is
getting inlined.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
@ 2012-09-05  7:50 ` jakub at gcc dot gnu.org
  2012-09-05  9:21 ` rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-09-05  7:50 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 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."


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
  2012-09-05  7:50 ` [Bug c++/54483] " jakub at gcc dot gnu.org
@ 2012-09-05  9:21 ` rguenth at gcc dot gnu.org
  2012-09-05 11:12 ` daniel.kruegler at googlemail dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-09-05  9:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-09-05 09:21:42 UTC ---
.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
  2012-09-05  7:50 ` [Bug c++/54483] " jakub at gcc dot gnu.org
  2012-09-05  9:21 ` rguenth at gcc dot gnu.org
@ 2012-09-05 11:12 ` daniel.kruegler at googlemail dot com
  2012-09-05 11:21 ` paolo.carlini at oracle dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-09-05 11:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 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)."


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (2 preceding siblings ...)
  2012-09-05 11:12 ` daniel.kruegler at googlemail dot com
@ 2012-09-05 11:21 ` paolo.carlini at oracle dot com
  2012-09-07  8:30 ` redi at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-09-05 11:21 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2012-09-05
         Resolution|INVALID                     |
     Ever Confirmed|0                           |1

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-09-05 11:21:06 UTC ---
Let's reopen this, then.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (3 preceding siblings ...)
  2012-09-05 11:21 ` paolo.carlini at oracle dot com
@ 2012-09-07  8:30 ` redi at gcc dot gnu.org
  2014-11-30 15:17 ` usack at math dot fu-berlin.de
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2012-09-07  8:30 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (4 preceding siblings ...)
  2012-09-07  8:30 ` redi at gcc dot gnu.org
@ 2014-11-30 15:17 ` usack at math dot fu-berlin.de
  2014-11-30 15:33 ` usack at math dot fu-berlin.de
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: usack at math dot fu-berlin.de @ 2014-11-30 15:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

Juisoo <usack at math dot fu-berlin.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |usack at math dot fu-berlin.de

--- Comment #6 from Juisoo <usack at math dot fu-berlin.de> ---
Created attachment 34147
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34147&action=edit
Files for testcase of initial post


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (5 preceding siblings ...)
  2014-11-30 15:17 ` usack at math dot fu-berlin.de
@ 2014-11-30 15:33 ` usack at math dot fu-berlin.de
  2014-11-30 15:34 ` usack at math dot fu-berlin.de
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: usack at math dot fu-berlin.de @ 2014-11-30 15:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

--- Comment #7 from Juisoo <usack at math dot fu-berlin.de> ---
Created attachment 34148
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34148&action=edit
second test case


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (6 preceding siblings ...)
  2014-11-30 15:33 ` usack at math dot fu-berlin.de
@ 2014-11-30 15:34 ` usack at math dot fu-berlin.de
  2015-03-26  8:47 ` kariya_mitsuru at hotmail dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: usack at math dot fu-berlin.de @ 2014-11-30 15:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

--- Comment #8 from Juisoo <usack at math dot fu-berlin.de> ---
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.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (7 preceding siblings ...)
  2014-11-30 15:34 ` usack at math dot fu-berlin.de
@ 2015-03-26  8:47 ` kariya_mitsuru at hotmail dot com
  2021-08-27 23:34 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-03-26  8:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

Mitsuru Kariya <kariya_mitsuru at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kariya_mitsuru at hotmail dot com

--- Comment #9 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
(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.)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (8 preceding siblings ...)
  2015-03-26  8:47 ` kariya_mitsuru at hotmail dot com
@ 2021-08-27 23:34 ` pinskia at gcc dot gnu.org
  2024-01-18  4:17 ` pinskia at gcc dot gnu.org
  2024-01-18  5:44 ` thiago at kde dot org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-27 23:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(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;

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (9 preceding siblings ...)
  2021-08-27 23:34 ` pinskia at gcc dot gnu.org
@ 2024-01-18  4:17 ` pinskia at gcc dot gnu.org
  2024-01-18  5:44 ` thiago at kde dot org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-18  4:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thiago at kde dot org

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 113465 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/54483] undefined reference to static constexpr in .so
  2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
                   ` (10 preceding siblings ...)
  2024-01-18  4:17 ` pinskia at gcc dot gnu.org
@ 2024-01-18  5:44 ` thiago at kde dot org
  11 siblings, 0 replies; 13+ messages in thread
From: thiago at kde dot org @ 2024-01-18  5:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54483

--- Comment #13 from Thiago Macieira <thiago at kde dot org> ---
(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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-01-18  5:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-04 18:31 [Bug c++/54483] New: undefined reference to static constexpr in .so baliga at gmail dot com
2012-09-05  7:50 ` [Bug c++/54483] " jakub at gcc dot gnu.org
2012-09-05  9:21 ` rguenth at gcc dot gnu.org
2012-09-05 11:12 ` daniel.kruegler at googlemail dot com
2012-09-05 11:21 ` paolo.carlini at oracle dot com
2012-09-07  8:30 ` redi at gcc dot gnu.org
2014-11-30 15:17 ` usack at math dot fu-berlin.de
2014-11-30 15:33 ` usack at math dot fu-berlin.de
2014-11-30 15:34 ` usack at math dot fu-berlin.de
2015-03-26  8:47 ` kariya_mitsuru at hotmail dot com
2021-08-27 23:34 ` pinskia at gcc dot gnu.org
2024-01-18  4:17 ` pinskia at gcc dot gnu.org
2024-01-18  5:44 ` thiago at kde dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).