[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 Jason Merrill jason at gcc dot gnu.org changed: What|Removed |Added Status|REOPENED|RESOLVED Resolution|--- |FIXED --- Comment #16 from Jason Merrill jason at gcc dot gnu.org --- I think these additional testcases should go on bug 65398, not this one; these cases also deal with the address of an array element.
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 Mitsuru Kariya kariya_mitsuru at hotmail dot com changed: What|Removed |Added Status|RESOLVED|REOPENED Resolution|FIXED |--- --- Comment #15 from Mitsuru Kariya kariya_mitsuru at hotmail dot com --- I found another sample like below. = sample code = constexpr char s[] = s; constexpr auto eq = (s[0] + 0) == (s[0] + 1); int main() {} = sample code = error message compare3.cpp:3:33: error: '(( s[0]) == (( s[0]) + 1u))' is not a constant expression constexpr auto eq = (s[0] + 0) == (s[0] + 1); error message Note that gcc 4.9.2 accepts it. cf. http://melpon.org/wandbox/permlink/RybrdNbUdtMi39wX
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 --- Comment #14 from Mitsuru Kariya kariya_mitsuru at hotmail dot com --- The rev.221737 seems to be able to compile the sample code above, but cannot compile another sample code like below. = sample code = constexpr char s1[] = s1; constexpr char s2[] = s2; constexpr auto eq = (s1 + 0) == (s2 + 1); int main() {} = sample code = error message compare2.cpp:4:30: error: '(((const char*)( s1)) == (((const char*)( s2)) + 1u))' is not a constant expression constexpr auto eq = (s1 + 0) == (s2 + 1); error message Although the first sample causes compilation error only in 5.0.0, the second sample causes compilation error in 4.9.2 too. cf. http://melpon.org/wandbox/permlink/KhcREuNqGofbZvqw
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 Jason Merrill jason at gcc dot gnu.org changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --- Comment #13 from Jason Merrill jason at gcc dot gnu.org --- Fixed.
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 --- Comment #12 from Jason Merrill jason at gcc dot gnu.org --- Author: jason Date: Fri Mar 27 16:36:32 2015 New Revision: 221737 URL: https://gcc.gnu.org/viewcvs?rev=221737root=gccview=rev Log: PR c++/65509 * decl.c (make_rtl_for_nonlocal_decl): Don't defer static constants. Added: trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-ptrcomp1.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 Jason Merrill jason at gcc dot gnu.org changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org --- Comment #11 from Jason Merrill jason at gcc dot gnu.org --- OK, the issue seems to be that make_rtl_for_nonlocal_decl in the front end is trying to defer calling rest_of_decl_compilation for static constant variables. Now that we have cgraph, the front end shouldn't be trying to play these types of games.
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 Marek Polacek mpolacek at gcc dot gnu.org changed: What|Removed |Added Target Milestone|--- |5.0 Summary|[C++11] GCC rejects |[5 Regression] [C++11] GCC |operator== with two |rejects operator== with two |distinct pointers as not|distinct pointers as not |constexpr |constexpr
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 Jakub Jelinek jakub at gcc dot gnu.org changed: What|Removed |Added CC||jakub at gcc dot gnu.org --- Comment #3 from Jakub Jelinek jakub at gcc dot gnu.org --- Yeah, it is r218462.
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 Jakub Jelinek jakub at gcc dot gnu.org changed: What|Removed |Added CC||hubicka at gcc dot gnu.org, ||jason at gcc dot gnu.org --- Comment #4 from Jakub Jelinek jakub at gcc dot gnu.org --- The difference between when i1 and i2 are constexprs and when they are not is that their cgraph nodes have definition = false if they are constexprs. Dunno if that is intentional or not.
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 --- Comment #7 from Marek Polacek mpolacek at gcc dot gnu.org --- (In reply to Jakub Jelinek from comment #4) The difference between when i1 and i2 are constexprs and when they are not is that their cgraph nodes have definition = false if they are constexprs. Dunno if that is intentional or not. True, they don't have definitions because we're trying to evaluate the constexpr comparison in cxx_eval_binary_expression before finalize_decl could create the definitions for i1 and i2.
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 --- Comment #9 from Jakub Jelinek jakub at gcc dot gnu.org --- (In reply to Marek Polacek from comment #8) The following (untested) should work: --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6113,6 +6113,7 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec) not emitted into the object file unnecessarily. */ filename = LOCATION_FILE (input_location); if (!DECL_VIRTUAL_P (decl) + !DECL_DECLARED_CONSTEXPR_P (decl) TREE_READONLY (decl) DECL_INITIAL (decl) != NULL_TREE DECL_INITIAL (decl) != error_mark_node My reasoning is that we shouldn't defer assembling the variable if it might be needed in the constexpr context. But in the #c5 testcase it isn't DECL_DECLARED_CONSTEXPR_P, is it?
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 --- Comment #8 from Marek Polacek mpolacek at gcc dot gnu.org --- The following (untested) should work: --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6113,6 +6113,7 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec) not emitted into the object file unnecessarily. */ filename = LOCATION_FILE (input_location); if (!DECL_VIRTUAL_P (decl) + !DECL_DECLARED_CONSTEXPR_P (decl) TREE_READONLY (decl) DECL_INITIAL (decl) != NULL_TREE DECL_INITIAL (decl) != error_mark_node My reasoning is that we shouldn't defer assembling the variable if it might be needed in the constexpr context.
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 --- Comment #10 from Marek Polacek mpolacek at gcc dot gnu.org --- (In reply to Jakub Jelinek from comment #9) But in the #c5 testcase it isn't DECL_DECLARED_CONSTEXPR_P, is it? True :(.
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 --- Comment #6 from Daniel Krügler daniel.kruegler at googlemail dot com --- (In reply to Jakub Jelinek from comment #5) const int i1 = 1; const int i2 = 2; constexpr auto b = i1 == i2; int main() {} is now also rejected, when it used to be accepted. Both behavioral changes look incorrect to me. The addresses of such global objects are valid for equality comparison irrespective whether they are constexpr or not, because == has no pre-condition: Two pointers compare equal if they are both null, both point to the same function, or both represent the same address (3.9.2), otherwise they compare unequal. therefore we cannot fall into the exclusion bullet within 5.20 p2 a relational (5.9) or equality (5.10) operator where the result is unspecified;
[Bug c++/65509] [5 Regression] [C++11] GCC rejects operator== with two distinct pointers as not constexpr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65509 --- Comment #5 from Jakub Jelinek jakub at gcc dot gnu.org --- const int i1 = 1; const int i2 = 2; constexpr auto b = i1 == i2; int main() {} is now also rejected, when it used to be accepted.