* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
@ 2011-07-29 10:06 ` rguenth at gcc dot gnu.org
2011-07-29 10:37 ` matthieu.imbert@ens-lyon.fr
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-07-29 10:06 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-29 10:05:49 UTC ---
You lack a definition of test<C>::version.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
2011-07-29 10:06 ` [Bug c++/49896] " rguenth at gcc dot gnu.org
@ 2011-07-29 10:37 ` matthieu.imbert@ens-lyon.fr
2011-07-29 12:50 ` matthieu.imbert@ens-lyon.fr
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: matthieu.imbert@ens-lyon.fr @ 2011-07-29 10:37 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
--- Comment #2 from Matthieu Imbert <matthieu.imbert@ens-lyon.fr> 2011-07-29 10:37:33 UTC ---
(In reply to comment #1)
> You lack a definition of test<C>::version.
C++ standard section 9.4.2 states:
If a 'static' data member is of 'const' integral or 'const' enumeral type,
its declaration in the class definition can specify a 'constant-initializer'
which shall be an integral constant expression (5.19). In that case, the
member can appear in integral constant expressions. The member shall still
be defined in a namespace scope if it is used in the program and the
namespace scope definition shall not contain an 'initializer'.
The notion of "used" is defined in section 3.2:
An object or non-overloaded function whose name appears as a potentially-
evaluated expression is used unless it is an object that satisfies the
requirements for appearing in a constant expression (5.19 [expr.const]) and
the
lvalue-to-rvalue conversion (4.1 [conv.lval]) is immediately applied.
I am not a C++ expert but various sources (for example: stroustrup C++ faq:
http://www2.research.att.com/~bs/bs_faq2.html#in-class) seem to say that the
code snippet i sent is valid since the address of test<C>::version is not
taken. Stroustrup says: "You can take the address of a static member if (and
only if) it has an out-of-class definition", which i interpret as: no need for
a definition if address not taken.
So in brief, i think there is no need to define test<C>::version to be correct.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
2011-07-29 10:06 ` [Bug c++/49896] " rguenth at gcc dot gnu.org
2011-07-29 10:37 ` matthieu.imbert@ens-lyon.fr
@ 2011-07-29 12:50 ` matthieu.imbert@ens-lyon.fr
2011-07-29 17:55 ` harald at gigawatt dot nl
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: matthieu.imbert@ens-lyon.fr @ 2011-07-29 12:50 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
Matthieu Imbert <matthieu.imbert@ens-lyon.fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
--- Comment #3 from Matthieu Imbert <matthieu.imbert@ens-lyon.fr> 2011-07-29 12:49:46 UTC ---
forgot to change bug state
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
` (2 preceding siblings ...)
2011-07-29 12:50 ` matthieu.imbert@ens-lyon.fr
@ 2011-07-29 17:55 ` harald at gigawatt dot nl
2011-07-30 12:10 ` redi at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: harald at gigawatt dot nl @ 2011-07-29 17:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
Harald van Dijk <harald at gigawatt dot nl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |harald at gigawatt dot nl
--- Comment #4 from Harald van Dijk <harald at gigawatt dot nl> 2011-07-29 17:55:21 UTC ---
0x80000000 is (possibly wrongly) rejected as an integer constant expression,
because it is not within int's range. It is accepted with an explicit cast.
With a slight modification, it triggers an ICE:
template<class C>
class test {
protected:
static const int versionConst = 0x80000000;
enum { versionEnum = versionConst };
public:
int getVersion();
};
template<class C>
int test<C>::getVersion() {
return versionEnum;
}
class dummy_class {};
int main() {
test<dummy_class> t;
return t.getVersion();
}
$ g++ -c test.cc
test.cc: In instantiation of ‘test<dummy_class>’:
test.cc:18:21: instantiated from here
test.cc:5:8: error: the value of ‘test<dummy_class>::versionConst’ is not
usable in a constant expression
test.cc:5:8: internal compiler error: in non_const_var_error, at
cp/semantics.c:6852
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.6.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/pkgbuild/sys-devel/gcc-4.6.1/work/gcc-4.6.1/configure
--build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --prefix=/usr
--enable-languages=c,c++,ada --enable-checking
Thread model: posix
gcc version 4.6.1 (GCC)
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
` (3 preceding siblings ...)
2011-07-29 17:55 ` harald at gigawatt dot nl
@ 2011-07-30 12:10 ` redi at gcc dot gnu.org
2011-07-30 14:59 ` harald at gigawatt dot nl
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2011-07-30 12:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-07-30 12:09:28 UTC ---
The initializer results in integer overflow which is undefined behaviour, so if
G++ accepts it but requires the variable to be defined then that is a
reasonable result.
The modified example shouldn't cause an ICE, that's a regression, but it seems
to be fixed in 4.7 already
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
` (4 preceding siblings ...)
2011-07-30 12:10 ` redi at gcc dot gnu.org
@ 2011-07-30 14:59 ` harald at gigawatt dot nl
2011-10-09 15:23 ` paolo.carlini at oracle dot com
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: harald at gigawatt dot nl @ 2011-07-30 14:59 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
--- Comment #6 from Harald van Dijk <harald at gigawatt dot nl> 2011-07-30 14:59:09 UTC ---
> The initializer results in integer overflow which is undefined behaviour
No, it doesn't result in integer overflow. 0x80000000 is a constant of type
unsigned int, which is implicitly converted to the desired type of int.
Converting an out-of-range integer value to a signed integer type is
implementation-defined which has been defined in GCC in a sensible way,
documented at
<http://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/Integers-implementation.html>.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
` (5 preceding siblings ...)
2011-07-30 14:59 ` harald at gigawatt dot nl
@ 2011-10-09 15:23 ` paolo.carlini at oracle dot com
2011-10-09 21:07 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-10-09 15:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jason at gcc dot gnu.org
--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-10-09 15:22:48 UTC ---
Jason, I guess we need a final word about the triage of this.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
` (6 preceding siblings ...)
2011-10-09 15:23 ` paolo.carlini at oracle dot com
@ 2011-10-09 21:07 ` jason at gcc dot gnu.org
2011-10-11 17:54 ` jason at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2011-10-09 21:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2011-10-09
AssignedTo|unassigned at gcc dot |jason at gcc dot gnu.org
|gnu.org |
Ever Confirmed|0 |1
--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> 2011-10-09 21:06:34 UTC ---
(In reply to comment #6)
Right. I was surprised by this, but conversion of out-of-range values between
integral types is treated differently in the standard from overflow in
arithmetic operations.
4.7:
If the destination type is signed, the value is unchanged if it can be
represented in the destination type (and bit-field width); otherwise, the value
is implementation-defined.
So, the testcase is OK. I think this bug is actually closely related to 49855,
as the fix for that bug also fixes this one for me.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
` (7 preceding siblings ...)
2011-10-09 21:07 ` jason at gcc dot gnu.org
@ 2011-10-11 17:54 ` jason at gcc dot gnu.org
2011-10-11 18:19 ` jason at gcc dot gnu.org
2011-10-11 18:22 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2011-10-11 17:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> 2011-10-11 17:53:20 UTC ---
Author: jason
Date: Tue Oct 11 17:53:07 2011
New Revision: 179813
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179813
Log:
PR c++/49855
PR c++/49896
* cp-tree.def (IMPLICIT_CONV_EXPR): New.
* call.c (perform_implicit_conversion_flags): Build it
instead of NOP_EXPR.
* cp-objcp-common.c (cp_common_init_ts): It's typed.
* cxx-pretty-print.c (pp_cxx_cast_expression): Handle it.
(pp_cxx_expression): Likewise.
* error.c (dump_expr): Likewise.
* semantics.c (potential_constant_expression_1): Likewise.
* tree.c (cp_tree_equal): Likewise.
(cp_walk_subtrees): Likewise.
* pt.c (iterative_hash_template_arg): Likewise.
(for_each_template_parm_r): Likewise.
(type_dependent_expression_p): Likewise.
(tsubst_copy, tsubst_copy_and_build): Handle IMPLICIT_CONV_EXPR
and CONVERT_EXPR.
* cp-tree.h (IMPLICIT_CONV_EXPR_DIRECT_INIT): New.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-template3.C
trunk/gcc/testsuite/g++.dg/template/constant1.C
trunk/gcc/testsuite/g++.dg/template/constant2.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/cp/cp-objcp-common.c
trunk/gcc/cp/cp-tree.def
trunk/gcc/cp/cp-tree.h
trunk/gcc/cp/cxx-pretty-print.c
trunk/gcc/cp/error.c
trunk/gcc/cp/pt.c
trunk/gcc/cp/semantics.c
trunk/gcc/cp/tree.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
` (8 preceding siblings ...)
2011-10-11 17:54 ` jason at gcc dot gnu.org
@ 2011-10-11 18:19 ` jason at gcc dot gnu.org
2011-10-11 18:22 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2011-10-11 18:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
--- Comment #10 from Jason Merrill <jason at gcc dot gnu.org> 2011-10-11 18:18:35 UTC ---
Author: jason
Date: Tue Oct 11 18:18:25 2011
New Revision: 179815
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=179815
Log:
PR c++/49855
PR c++/49896
* call.c (perform_implicit_conversion_flags): Do perform
scalar conversions in templates.
* pt.c (tsubst_copy, tsubst_copy_and_build): Handle CONVERT_EXPR.
Added:
branches/gcc-4_6-branch/gcc/testsuite/g++.dg/template/constant1.C
branches/gcc-4_6-branch/gcc/testsuite/g++.dg/template/constant2.C
Modified:
branches/gcc-4_6-branch/gcc/cp/ChangeLog
branches/gcc-4_6-branch/gcc/cp/call.c
branches/gcc-4_6-branch/gcc/cp/pt.c
branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/49896] undefined reference to static const integral member whose address is not used, for some values of the constant
2011-07-29 7:53 [Bug c++/49896] New: undefined reference to static const integral member whose address is not used, for some values of the constant matthieu.imbert@ens-lyon.fr
` (9 preceding siblings ...)
2011-10-11 18:19 ` jason at gcc dot gnu.org
@ 2011-10-11 18:22 ` jason at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2011-10-11 18:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.6.2
--- Comment #11 from Jason Merrill <jason at gcc dot gnu.org> 2011-10-11 18:20:52 UTC ---
Fixed for 4.6.2.
^ permalink raw reply [flat|nested] 12+ messages in thread