public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53585] New: template value parameter of pointer-to-member type incorrectly rejects non-direct values
@ 2012-06-06  1:15 yacwroy at gmail dot com
  2012-06-06  7:49 ` [Bug c++/53585] " daniel.kruegler at googlemail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: yacwroy at gmail dot com @ 2012-06-06  1:15 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53585

             Bug #: 53585
           Summary: template value parameter of pointer-to-member type
                    incorrectly rejects non-direct values
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: yacwroy@gmail.com


Created attachment 27561
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27561
c++ testcase - should be legal

Problem:
Pointer-to-member value parameters appear to only accept direct values (of the
immediate form &X::Y) and reject passed constexpr variables.

llvm/clang++ accepts these.

I'm assuming this is legal but I haven't checked the standard.

specs: linux/x64

source (same as attached)
=========================
struct SFoo
    {
        int x;
    };

constexpr int SFoo::* G_ptr_to_x = &SFoo::x;

// Dummy test struct.
template <int SFoo::* P>
struct SBar {};

SBar<G_ptr_to_x> G_bar; // <ERROR>. (This should be legal, and is in clang).

// Additional testing:
SBar<&SFoo::x> G_bar2; // Shows the member-pointer works if immediate.
constexpr int SFoo::* another_ptr = G_ptr_to_x; // Shows "could not convert
..." error message is incorrect.

int main()
    {}
=========================
Errors (build command = g++ mptr.cpp -std=c++11).
=========================
test/misc/mptr.cpp:12:16: error: ‘G_ptr_to_x’ is not a valid template argument
for type ‘int SFoo::*’
 SBar<G_ptr_to_x> G_bar; // <ERROR>. (This should be legal, and is in clang).
                ^
test/misc/mptr.cpp:12:16: error: it must be a pointer-to-member of the form
‘&X::Y’
test/misc/mptr.cpp:12:16: error: could not convert template argument
‘G_ptr_to_x’ to ‘int SFoo::*’
test/misc/mptr.cpp:12:23: error: invalid type in declaration before ‘;’ token
 SBar<G_ptr_to_x> G_bar; // <ERROR>. (This should be legal, and is in clang).
=========================


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/53585] template value parameter of pointer-to-member type incorrectly rejects non-direct values
  2012-06-06  1:15 [Bug c++/53585] New: template value parameter of pointer-to-member type incorrectly rejects non-direct values yacwroy at gmail dot com
@ 2012-06-06  7:49 ` daniel.kruegler at googlemail dot com
  2012-06-06 16:43 ` yacwroy at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-06-06  7:49 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53585

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler at
                   |                            |googlemail dot com

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-06-06 07:48:59 UTC ---
This looks like a clang extension to me, even though I must say that the
standard is currently not as clear as it could be (Keeping in mind that the
core language is currently considering to extend the valid forms of non-type
template parameters). The relevant wording from 14.3.2 p1 here is:

"A template-argument for a non-type, non-template template-parameter shall be
one of:
[..]
— a pointer to member expressed as described in 5.3.1."

I interpret this conservatively such that only an unary expression of the form
&qualified-id is valid here as described in p3+4 of 5.3.1.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/53585] template value parameter of pointer-to-member type incorrectly rejects non-direct values
  2012-06-06  1:15 [Bug c++/53585] New: template value parameter of pointer-to-member type incorrectly rejects non-direct values yacwroy at gmail dot com
  2012-06-06  7:49 ` [Bug c++/53585] " daniel.kruegler at googlemail dot com
@ 2012-06-06 16:43 ` yacwroy at gmail dot com
  2012-06-06 20:07 ` daniel.kruegler at googlemail dot com
  2014-07-08  9:02 ` paolo.carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: yacwroy at gmail dot com @ 2012-06-06 16:43 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53585

--- Comment #2 from Simon Hill <yacwroy at gmail dot com> 2012-06-06 16:43:41 UTC ---
Thats... really odd but OK. I guess I read it as you do, the key words being
"expressed as".

I wonder whether that was the intent, and if so, what their rationale was.
IMO it's very arbitrary and unintuitive, and for the life of me I can't think
of a reason.

Do you think it would be worth requesting a confirmation/clarification of this
from the C++ standard working group or similar? (I have no idea what that would
entail).

Thanks for checking this out.


For the moment I guess the workaround is to instead use a type-parameter and
require the type to contain a constexpr pointer-to-member.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/53585] template value parameter of pointer-to-member type incorrectly rejects non-direct values
  2012-06-06  1:15 [Bug c++/53585] New: template value parameter of pointer-to-member type incorrectly rejects non-direct values yacwroy at gmail dot com
  2012-06-06  7:49 ` [Bug c++/53585] " daniel.kruegler at googlemail dot com
  2012-06-06 16:43 ` yacwroy at gmail dot com
@ 2012-06-06 20:07 ` daniel.kruegler at googlemail dot com
  2014-07-08  9:02 ` paolo.carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-06-06 20:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53585

--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-06-06 20:06:56 UTC ---
(In reply to comment #2)
> I wonder whether that was the intent, and if so, what their rationale was.
> IMO it's very arbitrary and unintuitive, and for the life of me I can't think
> of a reason.

Yes, this was the intend, it is exactly the same wording as in C++03. When
C++11 was finished everyone was aware that the final rule where still overly
constraining and that relaxation of the current constraints is under
investigation.

> Do you think it would be worth requesting a confirmation/clarification of this
> from the C++ standard working group or similar? (I have no idea what that would
> entail).

I don't think that a clarification is needed. There is already active work to
relax the existing rules, but that is not C++11 as specified.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/53585] template value parameter of pointer-to-member type incorrectly rejects non-direct values
  2012-06-06  1:15 [Bug c++/53585] New: template value parameter of pointer-to-member type incorrectly rejects non-direct values yacwroy at gmail dot com
                   ` (2 preceding siblings ...)
  2012-06-06 20:07 ` daniel.kruegler at googlemail dot com
@ 2014-07-08  9:02 ` paolo.carlini at oracle dot com
  3 siblings, 0 replies; 5+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-07-08  9:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53585

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Current clang rejects it.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-07-08  9:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-06  1:15 [Bug c++/53585] New: template value parameter of pointer-to-member type incorrectly rejects non-direct values yacwroy at gmail dot com
2012-06-06  7:49 ` [Bug c++/53585] " daniel.kruegler at googlemail dot com
2012-06-06 16:43 ` yacwroy at gmail dot com
2012-06-06 20:07 ` daniel.kruegler at googlemail dot com
2014-07-08  9:02 ` 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).