Re: [PATCH] PR c++/52343 - error with alias template as template template argument
OK. Jason
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
Jason Merrill ja...@redhat.com writes: On 12/21/2012 07:35 AM, Dodji Seketeli wrote: else if (TREE_TYPE (t) INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (t)) -!TREE_CONSTANT (t)) +!TREE_CONSTANT (t) + /* Class template and alias template arguments should be OK. */ +!DECL_TYPE_TEMPLATE_P (t)) Instead, let's add a previous else if to catch template template arguments (and do nothing) so that when we hit this else if, we know we're dealing with a non-type argument. Right. Here you go. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/cp/ PR c++/52343 * pt.c (check_instantiated_arg): Allow type template arguments. gcc/testsuite/ PR c++/52343 * g++.dg/cpp0x/alias-decl-29.C: New test. --- gcc/cp/pt.c| 3 +++ gcc/testsuite/g++.dg/cpp0x/alias-decl-29.C | 10 ++ 2 files changed, 13 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/alias-decl-29.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1b3f039..9e99c09 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14421,6 +14421,9 @@ check_instantiated_arg (tree tmpl, tree t, tsubst_flags_t complain) return true; } } + /* Class template and alias template arguments should be OK. */ + else if (DECL_TYPE_TEMPLATE_P (t)) +; /* A non-type argument of integral or enumerated type must be a constant. */ else if (TREE_TYPE (t) diff --git a/gcc/testsuite/g++.dg/cpp0x/alias-decl-29.C b/gcc/testsuite/g++.dg/cpp0x/alias-decl-29.C new file mode 100644 index 000..f6cc695 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/alias-decl-29.C @@ -0,0 +1,10 @@ +// Origin: PR c++/52343 +// { dg-do compile { target c++11 } } + +templatetypename +using A = int; + +templatetemplateclass class +struct B {}; + +BA b; -- Dodji
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
Gabriel Dos Reis g...@integrable-solutions.net writes: G On Sun, Dec 23, 2012 at 11:04 PM, Jason Merrill ja...@redhat.com wrote: On 12/21/2012 07:35 AM, Dodji Seketeli wrote: else if (TREE_TYPE (t) INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (t)) - !TREE_CONSTANT (t)) + !TREE_CONSTANT (t) + /* Class template and alias template arguments should be OK. */ + !DECL_TYPE_TEMPLATE_P (t)) Instead, let's add a previous else if to catch template template arguments (and do nothing) so that when we hit this else if, we know we're dealing with a non-type argument. Thanks; that would make the logic clearer. I would suggest that we abstract this series of conjunction into a separate (static inline) function, e.g. nontype_argument_p. These conjunctions represents a non-type argument only if they are satisfied /and/ the previous 'if' branches are not taken. So just putting the conjunctions in e.g, nontype_argument_p could be seen as confusion too, IMHO. Could we just consider that the patch + comment of my earlier message and the comment of these conjunctions /* A non-type argument of integral or enumerated type must be a constant. */ should make this less confusing? -- Dodji
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
On 12/21/2012 07:35 AM, Dodji Seketeli wrote: else if (TREE_TYPE (t) INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (t)) - !TREE_CONSTANT (t)) + !TREE_CONSTANT (t) + /* Class template and alias template arguments should be OK. */ + !DECL_TYPE_TEMPLATE_P (t)) Instead, let's add a previous else if to catch template template arguments (and do nothing) so that when we hit this else if, we know we're dealing with a non-type argument. Jason
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
On Sun, Dec 23, 2012 at 11:04 PM, Jason Merrill ja...@redhat.com wrote: On 12/21/2012 07:35 AM, Dodji Seketeli wrote: else if (TREE_TYPE (t) INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (t)) - !TREE_CONSTANT (t)) + !TREE_CONSTANT (t) + /* Class template and alias template arguments should be OK. */ + !DECL_TYPE_TEMPLATE_P (t)) Instead, let's add a previous else if to catch template template arguments (and do nothing) so that when we hit this else if, we know we're dealing with a non-type argument. Thanks; that would make the logic clearer. I would suggest that we abstract this series of conjunction into a separate (static inline) function, e.g. nontype_argument_p. -- Gaby
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
Gabriel Dos Reis g...@integrable-solutions.net writes: Thank you very much for the explanation; your previous message makes sense to me now. You are welcome. The question I have is why are we using TREE_TYPE of a TEMPLATE_DECL to represent the current instantiation of a template alias? My understanding is that in the instantiation at line 7 below 1 templatetypename 2 using A = int; 3 4 templatetemplateclass class 5 struct B {}; 6 7 BA b; check_instantiated_arg is not looking at the current instantiation of the template alias A. Rather, it is looking at the template-name A (which resolved, IMHO rightfully, to the decl for A which happens to be a TEMPLATE_DECL). This seems consistent with the fact that the parameter of B is a template itself so its argument ought to be template-name, rather than a template instantiation. -- Dodji
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
On Sat, Dec 22, 2012 at 9:53 AM, Dodji Seketeli do...@redhat.com wrote: Gabriel Dos Reis g...@integrable-solutions.net writes: Thank you very much for the explanation; your previous message makes sense to me now. You are welcome. The question I have is why are we using TREE_TYPE of a TEMPLATE_DECL to represent the current instantiation of a template alias? My understanding is that in the instantiation at line 7 below 1 templatetypename 2 using A = int; 3 4 templatetemplateclass class 5 struct B {}; 6 7 BA b; check_instantiated_arg is not looking at the current instantiation of the template alias A. Rather, it is looking at the template-name A (which resolved, IMHO rightfully, to the decl for A which happens to be a TEMPLATE_DECL). This seems consistent with the fact that the parameter of B is a template itself so its argument ought to be template-name, rather than a template instantiation. Sorry for the confusion, current instantiation was the wrong word. What I meant to say was that the use and interpretation of TREE_TYPE is very confusing in this context. -- Gaby
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
The example is valid, but I am not sure I understand your explanation... -- Gaby
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
Gabriel Dos Reis g...@integrable-solutions.net writes: The example is valid, but I am not sure I understand your explanation... Ah, sorry. I realize just now that I haven't mentioned the initial erratic behaviour. Maybe that could have made my message easier to understand. So consider the test case of the message: 1 templatetypename 2 using A = int; 3 4 templatetemplateclass class 5 struct B {}; 6 7 BA b; test.cc:7:4: error: integral expression ‘A’ is not constant BA b; ^ Followed by some irrelevant other error messages. As I was saying my earlier message, here, the TREE_TYPE of the template_decl A is an integer; so check_instantiated_arg takes it as if A is an integer value (a decl with integer type), and thus, should be a constant. The fix I am proposing is just to allow check_instantiated_arg to make the difference between a classical integer decl, and an alias template which type-id is an integer. -- Dodji
Re: [PATCH] PR c++/52343 - error with alias template as template template argument
On Fri, Dec 21, 2012 at 10:25 AM, Dodji Seketeli do...@redhat.com wrote: Gabriel Dos Reis g...@integrable-solutions.net writes: The example is valid, but I am not sure I understand your explanation... Ah, sorry. I realize just now that I haven't mentioned the initial erratic behaviour. Maybe that could have made my message easier to understand. So consider the test case of the message: 1 templatetypename 2 using A = int; 3 4 templatetemplateclass class 5 struct B {}; 6 7 BA b; test.cc:7:4: error: integral expression ‘A’ is not constant BA b; ^ Followed by some irrelevant other error messages. As I was saying my earlier message, here, the TREE_TYPE of the template_decl A is an integer; so check_instantiated_arg takes it as if A is an integer value (a decl with integer type), and thus, should be a constant. The fix I am proposing is just to allow check_instantiated_arg to make the difference between a classical integer decl, and an alias template which type-id is an integer. -- Dodji Hi Dodji, Thank you very much for the explanation; your previous message makes sense to me now. The question I have is why are we using TREE_TYPE of a TEMPLATE_DECL to represent the current instantiation of a template alias? Should not we use TEMPLATE_RESULT instead? -- Gaby