public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug c++/52902] New: Pointer to member rejected in constant expression @ 2012-04-07 17:31 freunddeslichts at web dot de 2015-09-04 14:07 ` [Bug c++/52902] " trippels at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: freunddeslichts at web dot de @ 2012-04-07 17:31 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52902 Bug #: 52902 Summary: Pointer to member rejected in constant expression Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: freunddeslichts@web.de ######################################################################### struct X { int a; }; constexpr int X::* mem = &X::a; void foo() { constexpr X x = {1}; constexpr int k = x.a; // ok constexpr int l = x.*mem; // should be ok <------------------ //constexpr int const* m = &(x.a); // legitimate error } ######################################################################### g++-4.7 -std=c++0x bug.cpp -o g47.out bug.cpp: In function ‘void foo()’: bug.cpp:29:24: error: ‘(const int*)(& x)’ is not a constant expression ######################################################################### As far as I can see, a pointer to member access should be a constant expresssion, iff both the object and the pointer are constant expressions. This behaviour is shown by the clang++ compiler, which does not emit the above error. It seems gcc evalutates the expression x.*mem as something like *((const int*)(& x) + mem) In this implementation, the left (intermediate) operand to the + operator is not a constant expression, that's why gcc rejects it by mistake. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/52902] Pointer to member rejected in constant expression 2012-04-07 17:31 [Bug c++/52902] New: Pointer to member rejected in constant expression freunddeslichts at web dot de @ 2015-09-04 14:07 ` trippels at gcc dot gnu.org 2015-09-04 14:14 ` trippels at gcc dot gnu.org ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: trippels at gcc dot gnu.org @ 2015-09-04 14:07 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52902 Markus Trippelsdorf <trippels at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ldionne.2 at gmail dot com --- Comment #1 from Markus Trippelsdorf <trippels at gcc dot gnu.org> --- *** Bug 67376 has been marked as a duplicate of this bug. *** ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/52902] Pointer to member rejected in constant expression 2012-04-07 17:31 [Bug c++/52902] New: Pointer to member rejected in constant expression freunddeslichts at web dot de 2015-09-04 14:07 ` [Bug c++/52902] " trippels at gcc dot gnu.org @ 2015-09-04 14:14 ` trippels at gcc dot gnu.org 2015-09-04 14:28 ` trippels at gcc dot gnu.org 2015-09-04 14:52 ` paolo.carlini at oracle dot com 3 siblings, 0 replies; 5+ messages in thread From: trippels at gcc dot gnu.org @ 2015-09-04 14:14 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52902 Markus Trippelsdorf <trippels at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2015-09-04 CC| |trippels at gcc dot gnu.org Blocks| |55004 Ever confirmed|0 |1 Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55004 [Bug 55004] [meta-bug] constexpr issues ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/52902] Pointer to member rejected in constant expression 2012-04-07 17:31 [Bug c++/52902] New: Pointer to member rejected in constant expression freunddeslichts at web dot de 2015-09-04 14:07 ` [Bug c++/52902] " trippels at gcc dot gnu.org 2015-09-04 14:14 ` trippels at gcc dot gnu.org @ 2015-09-04 14:28 ` trippels at gcc dot gnu.org 2015-09-04 14:52 ` paolo.carlini at oracle dot com 3 siblings, 0 replies; 5+ messages in thread From: trippels at gcc dot gnu.org @ 2015-09-04 14:28 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52902 Markus Trippelsdorf <trippels at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #2 from Markus Trippelsdorf <trippels at gcc dot gnu.org> --- Works with gcc-5 and trunk. Closing. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/52902] Pointer to member rejected in constant expression 2012-04-07 17:31 [Bug c++/52902] New: Pointer to member rejected in constant expression freunddeslichts at web dot de ` (2 preceding siblings ...) 2015-09-04 14:28 ` trippels at gcc dot gnu.org @ 2015-09-04 14:52 ` paolo.carlini at oracle dot com 3 siblings, 0 replies; 5+ messages in thread From: paolo.carlini at oracle dot com @ 2015-09-04 14:52 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52902 Paolo Carlini <paolo.carlini at oracle dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |5.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-09-04 14:52 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2012-04-07 17:31 [Bug c++/52902] New: Pointer to member rejected in constant expression freunddeslichts at web dot de 2015-09-04 14:07 ` [Bug c++/52902] " trippels at gcc dot gnu.org 2015-09-04 14:14 ` trippels at gcc dot gnu.org 2015-09-04 14:28 ` trippels at gcc dot gnu.org 2015-09-04 14:52 ` 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).