public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56251] New: no DW_AT_const_value  for static const member of a template class
@ 2013-02-08  4:06 chihin.ko at oracle dot com
  2013-02-08  4:09 ` [Bug c++/56251] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: chihin.ko at oracle dot com @ 2013-02-08  4:06 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56251
           Summary: no DW_AT_const_value  for static const member of a
                    template class
    Classification: Unclassified
           Product: gcc
           Version: 4.6.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: chihin.ko@oracle.com


If a static const member is in template class, there is no DW_AT_const_value
info,
compare these tvalue/value


< 2><0x0000005a>      DW_TAG_member
                        DW_AT_name                  "value"
                        DW_AT_decl_file             0x00000001 t.cc
                        DW_AT_decl_line             0x00000009
                        DW_AT_type                  <0x00000069>
                        DW_AT_external              yes(1)
                        DW_AT_declaration           yes(1)
                        DW_AT_const_value           200(as signed = -56)  <===
const value
< 1><0x00000069>    DW_TAG_const_type
                      DW_AT_type                  <0x0000002c>

---------------------------------------------------------------------------------

< 2><0x0000007a>      DW_TAG_member
                        DW_AT_name                  "tvalue"
                        DW_AT_decl_file             0x00000001 t.cc
                        DW_AT_decl_line             0x00000005
                        DW_AT_type                  <0x00000069>
                        DW_AT_external              yes(1)
                        DW_AT_declaration           yes(1)
                                                                    <==== no
const value
< 2><0x00000087>      DW_TAG_template_type_parameter
                        DW_AT_name                  "T0"


cat t.cc

#include <stdio.h>

template<class T0, class T1>
struct TCC {
        static const T0 tvalue = 100;
};

struct CC {
        static const int value = 200;
};

int main()
{
    CC cc;
    TCC<int, int> tcc;

        printf("tcc.value1 = %u \n", tcc.tvalue);
        printf("cc.value1 = %u \n", cc.value);
}


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

* [Bug c++/56251] no DW_AT_const_value  for static const member of a template class
  2013-02-08  4:06 [Bug c++/56251] New: no DW_AT_const_value for static const member of a template class chihin.ko at oracle dot com
@ 2013-02-08  4:09 ` pinskia at gcc dot gnu.org
  2013-02-08 21:25 ` chihin.ko at oracle dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-02-08  4:09 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-02-08 04:08:35 UTC ---
This code is invalid code.


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

* [Bug c++/56251] no DW_AT_const_value  for static const member of a template class
  2013-02-08  4:06 [Bug c++/56251] New: no DW_AT_const_value for static const member of a template class chihin.ko at oracle dot com
  2013-02-08  4:09 ` [Bug c++/56251] " pinskia at gcc dot gnu.org
@ 2013-02-08 21:25 ` chihin.ko at oracle dot com
  2013-02-08 21:29 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: chihin.ko at oracle dot com @ 2013-02-08 21:25 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from chihin ko <chihin.ko at oracle dot com> 2013-02-08 21:24:55 UTC ---
How is it invalid ? it was compilable and runnable:

benjamin2 906> /pkg/gnu/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/pkg/gnu/bin/g++-4.7.1-5.10
COLLECT_LTO_WRAPPER=/pkg/gnu/libexec/gcc/i386-pc-solaris2.10/4.7.1/lto-wrapper
Target: i386-pc-solaris2.10
Configured with: ../gcc-4.7.1-src/configure --prefix=/pkg/gnu
--with-as=/pkg/gnu/bin/gas --with-gnu-as --enable-languages=c++,fortran
--enable-shared --enable-shared --with-gmp=/pkg/gnu --with-mpc=/pkg/local
--with-boot-ldflags=-R/pkg/local/lib:/pkg/gnu/lib --program-suffix=-4.7.1-5.10
Thread model: posix
gcc version 4.7.1 (GCC) 

benjamin2 907> /pkg/gnu/bin/g++ -std=c++11 -R/pkg/gnu/lib t1.cc

benjamin2 908> a.out
tcc.value1 = 100 
cc.value1 = 200


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

* [Bug c++/56251] no DW_AT_const_value  for static const member of a template class
  2013-02-08  4:06 [Bug c++/56251] New: no DW_AT_const_value for static const member of a template class chihin.ko at oracle dot com
  2013-02-08  4:09 ` [Bug c++/56251] " pinskia at gcc dot gnu.org
  2013-02-08 21:25 ` chihin.ko at oracle dot com
@ 2013-02-08 21:29 ` pinskia at gcc dot gnu.org
  2013-02-08 22:02 ` chihin.ko at oracle dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-02-08 21:29 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-02-08 21:28:25 UTC ---
You only declare the variable.  There is no definition of the variable in the
program.


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

* [Bug c++/56251] no DW_AT_const_value  for static const member of a template class
  2013-02-08  4:06 [Bug c++/56251] New: no DW_AT_const_value for static const member of a template class chihin.ko at oracle dot com
                   ` (2 preceding siblings ...)
  2013-02-08 21:29 ` pinskia at gcc dot gnu.org
@ 2013-02-08 22:02 ` chihin.ko at oracle dot com
  2013-02-08 22:10 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: chihin.ko at oracle dot com @ 2013-02-08 22:02 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from chihin ko <chihin.ko at oracle dot com> 2013-02-08 22:01:36 UTC ---
Note, this is a const static member, the initialization is the definition,
if I don't initialize it, I would get an "Undefined symbol" linking error.
This code is valid.


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

* [Bug c++/56251] no DW_AT_const_value  for static const member of a template class
  2013-02-08  4:06 [Bug c++/56251] New: no DW_AT_const_value for static const member of a template class chihin.ko at oracle dot com
                   ` (3 preceding siblings ...)
  2013-02-08 22:02 ` chihin.ko at oracle dot com
@ 2013-02-08 22:10 ` pinskia at gcc dot gnu.org
  2013-02-08 22:51 ` paolo.carlini at oracle dot com
  2013-02-10 16:00 ` daniel.kruegler at googlemail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-02-08 22:10 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2013-02-08 22:09:58 UTC ---
(In reply to comment #4)
> Note, this is a const static member, the initialization is the definition,
> if I don't initialize it, I would get an "Undefined symbol" linking error.
> This code is valid.

No, the code is invalid but a diagnostic is not required by the standard which
is why it is accepted.


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

* [Bug c++/56251] no DW_AT_const_value  for static const member of a template class
  2013-02-08  4:06 [Bug c++/56251] New: no DW_AT_const_value for static const member of a template class chihin.ko at oracle dot com
                   ` (4 preceding siblings ...)
  2013-02-08 22:10 ` pinskia at gcc dot gnu.org
@ 2013-02-08 22:51 ` paolo.carlini at oracle dot com
  2013-02-10 16:00 ` daniel.kruegler at googlemail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-02-08 22:51 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-02-08 22:50:35 UTC ---
See, eg, c++/30745 and many duplicates elsewhere.


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

* [Bug c++/56251] no DW_AT_const_value  for static const member of a template class
  2013-02-08  4:06 [Bug c++/56251] New: no DW_AT_const_value for static const member of a template class chihin.ko at oracle dot com
                   ` (5 preceding siblings ...)
  2013-02-08 22:51 ` paolo.carlini at oracle dot com
@ 2013-02-10 16:00 ` daniel.kruegler at googlemail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-02-10 16:00 UTC (permalink / raw)
  To: gcc-bugs


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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #7 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2013-02-10 16:00:42 UTC ---
(In reply to comment #6)
I agree with Paolo and Andrew when considered as a potentially C++03 code, but
I would like to add that the example code is indeed valid in C++11, because
ellipsis functions such as printf have an lvalue-to-rvalue semantics for the
function arguments and the ODR rule has been revised to say

"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)."

Of-course this allowance doesn't require that an implementation needs to add
"DW_AT_const_value" for such static const members: The rule only reflects
existing practice that this use-case is no ODR-usage of CC::value or of
TCC<int, int>::tvalue, respectively.


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

end of thread, other threads:[~2013-02-10 16:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-08  4:06 [Bug c++/56251] New: no DW_AT_const_value for static const member of a template class chihin.ko at oracle dot com
2013-02-08  4:09 ` [Bug c++/56251] " pinskia at gcc dot gnu.org
2013-02-08 21:25 ` chihin.ko at oracle dot com
2013-02-08 21:29 ` pinskia at gcc dot gnu.org
2013-02-08 22:02 ` chihin.ko at oracle dot com
2013-02-08 22:10 ` pinskia at gcc dot gnu.org
2013-02-08 22:51 ` paolo.carlini at oracle dot com
2013-02-10 16:00 ` daniel.kruegler at googlemail dot com

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).