public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53166] New: static_assert produces bogus warning
@ 2012-04-30 10:20 andyg1001 at hotmail dot co.uk
2012-04-30 10:52 ` [Bug c++/53166] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: andyg1001 at hotmail dot co.uk @ 2012-04-30 10:20 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53166
Bug #: 53166
Summary: static_assert produces bogus warning
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: andyg1001@hotmail.co.uk
The following code produces a bogus compilation warning:
template <typename X, X a>
struct A {
static_assert(a != nullptr, "oops");
};
int a1;
A<int*, &a1> a2; // this produces a bogus warning
A<int*, nullptr> a3; // correctly generates static assertion
The bogus warning is for the declaration of "a2" saying "the address of ‘a1’
will never be NULL". This is, of course, true but is exactly what the
static_assert is intended to ensure! (cf. the declaration of "a3"). Here is
the output from gcc:
$ gcc-4.7 -c --std=c++11 bugreport.cpp -Wall -Werror
bugreport.cpp: In instantiation of ‘struct A<int*, (& a1)>’:
bugreport.cpp:7:14: required from here
bugreport.cpp:2:10: error: the address of ‘a1’ will never be NULL
[-Werror=address]
bugreport.cpp: In instantiation of ‘struct A<int*, 0u>’:
bugreport.cpp:8:18: required from here
bugreport.cpp:3:5: error: static assertion failed: oops
cc1plus: all warnings being treated as errors
My expectation would be that the static_assert should silently pass, not cause
a warning in this case. Compare the output that clang gives:
bugreport.cpp:3:5: error: static_assert failed "oops"
static_assert(a != nullptr, "oops");
^ ~~~~~~~~~~~~
bugreport.cpp:8:18: note: in instantiation of template class 'A<int *,
nullptr>' requested here
A<int*, nullptr> a3; // correctly generates static assertion
^
1 error generated.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/53166] static_assert produces bogus warning
2012-04-30 10:20 [Bug c++/53166] New: static_assert produces bogus warning andyg1001 at hotmail dot co.uk
@ 2012-04-30 10:52 ` redi at gcc dot gnu.org
2012-05-04 1:39 ` paolo.carlini at oracle dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2012-04-30 10:52 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53166
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Status|UNCONFIRMED |NEW
Last reconfirmed| |2012-04-30
Ever Confirmed|0 |1
Severity|major |normal
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/53166] static_assert produces bogus warning
2012-04-30 10:20 [Bug c++/53166] New: static_assert produces bogus warning andyg1001 at hotmail dot co.uk
2012-04-30 10:52 ` [Bug c++/53166] " redi at gcc dot gnu.org
@ 2012-05-04 1:39 ` paolo.carlini at oracle dot com
2012-05-04 15:02 ` paolo at gcc dot gnu.org
2012-05-04 15:03 ` paolo.carlini at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-05-04 1:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53166
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |paolo.carlini at oracle dot
|gnu.org |com
Target Milestone|--- |4.8.0
--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-05-04 01:38:49 UTC ---
Seems easy.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/53166] static_assert produces bogus warning
2012-04-30 10:20 [Bug c++/53166] New: static_assert produces bogus warning andyg1001 at hotmail dot co.uk
2012-04-30 10:52 ` [Bug c++/53166] " redi at gcc dot gnu.org
2012-05-04 1:39 ` paolo.carlini at oracle dot com
@ 2012-05-04 15:02 ` paolo at gcc dot gnu.org
2012-05-04 15:03 ` paolo.carlini at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: paolo at gcc dot gnu.org @ 2012-05-04 15:02 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53166
--- Comment #2 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> 2012-05-04 15:02:10 UTC ---
Author: paolo
Date: Fri May 4 15:02:05 2012
New Revision: 187165
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187165
Log:
/cp
2012-05-04 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53166
* pt.c (instantiate_class_template_1): Increase / decrease
c_inhibit_evaluation_warnings around the tsubst_expr call
for STATIC_ASSERT_CONDITION.
(tsubst_expr, case STATIC_ASSERT): Likewise.
* typeck.c (cp_build_binary_op, case EQ_EXPR/NE_EXPR): Check
c_inhibit_evaluation_warnings in the OPT_Waddress warnings.
/testsuite
2012-05-04 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53166
* g++.dg/cpp0x/static_assert7.C: New.
Added:
trunk/gcc/testsuite/g++.dg/cpp0x/static_assert7.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/pt.c
trunk/gcc/cp/typeck.c
trunk/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/53166] static_assert produces bogus warning
2012-04-30 10:20 [Bug c++/53166] New: static_assert produces bogus warning andyg1001 at hotmail dot co.uk
` (2 preceding siblings ...)
2012-05-04 15:02 ` paolo at gcc dot gnu.org
@ 2012-05-04 15:03 ` paolo.carlini at oracle dot com
3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-05-04 15:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53166
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-05-04 15:03:17 UTC ---
Fixed for 4.8.0.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-05-04 15:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-30 10:20 [Bug c++/53166] New: static_assert produces bogus warning andyg1001 at hotmail dot co.uk
2012-04-30 10:52 ` [Bug c++/53166] " redi at gcc dot gnu.org
2012-05-04 1:39 ` paolo.carlini at oracle dot com
2012-05-04 15:02 ` paolo at gcc dot gnu.org
2012-05-04 15:03 ` paolo.carlini at oracle 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).