GCC rejects the following code (partly adapted from Boost's tribool), which I think is valid: struct dummy { void nonnull() {}; }; typedef void (dummy::*safe_bool)(); constexpr safe_bool a = &dummy::nonnull; static_assert( static_cast<bool>( a ), "" ); int main () { return 0; } I'm compiling with -std=c++14 and I'm seeing these errors: <source>:9:1: error: non-constant condition for static assertion static_assert( static_cast<bool>( a ), "" ); ^~~~~~~~~~~~~ <source>:9:16: error: '(dummy::nonnull != 0)' is not a constant expression static_assert( static_cast<bool>( a ), "" ); ^~~~~~~~~~~~~~~~~~~~~~ Compiler exited with result code 1 This code is accepted by Clang. This looks related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71896 but that has status "RESOLVED FIXED" but I'm seeing this on "GCC 7 (snapshot)" on godbolt.org (see https://godbolt.org/g/JnrZss ) as well as on my GCC 6.2.0.
*** Bug 85823 has been marked as a duplicate of this bug. ***
Created attachment 44167 [details] proposed fix https://gcc.gnu.org/ml/gcc-patches/2018-05/msg00968.html
Author: jason Date: Fri May 25 16:44:55 2018 New Revision: 260762 URL: https://gcc.gnu.org/viewcvs?rev=260762&root=gcc&view=rev Log: PR c++/80485 - inline function non-zero address. * symtab.c (nonzero_address): Check DECL_COMDAT. Added: trunk/gcc/testsuite/g++.dg/expr/pmf-3.C Modified: trunk/gcc/ChangeLog trunk/gcc/symtab.c
Author: jason Date: Mon Jun 11 18:56:56 2018 New Revision: 261449 URL: https://gcc.gnu.org/viewcvs?rev=261449&root=gcc&view=rev Log: PR c++/80485 - inline function non-zero address. * symtab.c (nonzero_address): Check DECL_COMDAT. Added: branches/gcc-8-branch/gcc/testsuite/g++.dg/expr/pmf-3.C Modified: branches/gcc-8-branch/gcc/ChangeLog branches/gcc-8-branch/gcc/symtab.c
Thanks to all for all work on this. (Apologies if this isn't helpful but just in case it is...) I notice that the original Godbolt snippet ( https://godbolt.org/g/JnrZss ) has regressed from a rejects-valid in 8.1 to an ICE on trunk ("9.0.0 20180610") : g++: internal compiler error: Segmentation fault signal terminated program as Please submit a full bug report, with preprocessed source if appropriate. See <https://gcc.gnu.org/bugs/> for instructions. Compiler returned: 4
(In reply to Tony E Lewis from comment #5) > Thanks to all for all work on this. > > (Apologies if this isn't helpful but just in case it is...) I notice that > the original Godbolt snippet ( https://godbolt.org/g/JnrZss ) has regressed > from a rejects-valid in 8.1 to an ICE on trunk ("9.0.0 20180610") : I don't see that. This compiles fine with trunk: struct dummy { void nonnull() {}; }; typedef void (dummy::*safe_bool)(); constexpr safe_bool a = &dummy::nonnull; static_assert( static_cast<bool>( a ), "" ); int main () { return 0; }
Ah yes - I'm seeing it compiling cleanly now on Godbolt's trunk (9.0.0 20180615). Must have been a temporary glitch in the build (and couldn't possibly have been due to my error :P ).
As far as I can see on Godbolt, this is now fixed in trunk. I'm happy for this issue to be closed.
Jason, I assume you don't plan to backport this to gcc-7-branch?
*** Bug 67245 has been marked as a duplicate of this bug. ***
*** Bug 100498 has been marked as a duplicate of this bug. ***
Fixed.