This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
- From: "kariya_mitsuru at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 30 Mar 2015 07:24:23 +0000
- Subject: [Bug c++/65398] [5 Regression] [C++11] GCC rejects constexpr variable definitions with valid initialization
- Auto-submitted: auto-generated
- References: <bug-65398-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65398
--- Comment #6 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
I also found a strange behavior like below.
============================== sample code ==============================
#include <iostream>
constexpr char s1[] = "s1";
constexpr char s2[] = "s2";
bool f(const char* p1, const char* p2) { return p1 == p2; }
constexpr auto eq1 = &s1[sizeof(s1)] == &s2[0];
auto eq2 = f(&s1[sizeof(s1)], &s2[0]);
int main()
{
std::cout << static_cast<const void*>(&s1[sizeof(s1)]) << std::endl;
std::cout << static_cast<const void*>(&s2[0]) << std::endl;
std::cout << std::boolalpha << eq1 << ", " << eq2 << std::endl;
}
============================== sample code ==============================
============================== output ==============================
0x400bb8
0x400bb8
false, true
============================== output ==============================
cf. http://melpon.org/wandbox/permlink/Iu0rFFMgeYqT98fo
I think that it should either
1) cause a compilation error at the definition of the eq1 if the result of
"&s1[sizeof(s1)] == &s2[0]" is "unspecified".
or
2) output "true, true" because both the "&s1[sizeof(s1)]" and "&s2[0]"
represent the same address.
but I am not sure which behavior is appropriate.
(I cannot find an explicit description by which comparison between one past the
end pointer and another object's pointer is "unspecified behavior", in the C++
standard.)