* [RFC] PR 50837
@ 2011-11-10 0:33 Paolo Carlini
2011-11-10 1:54 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2011-11-10 0:33 UTC (permalink / raw)
To: gcc-patches; +Cc: Jason Merrill
Hi,
I'm trying to make progress on this issue which I find rather
embarrassing in terms of simple uses of constexpr functions and
static_assert. We reject, at instantiation time:
template<class T>
struct z
{
static constexpr bool test_constexpr()
{
return true;
}
static void test()
{
static_assert(test_constexpr(), "test1"); //error here
}
};
‘static constexpr bool z<T>::test_constexpr() [with T = int]’ cannot
appear in a constant-expression
The same snippet is accepted if struct z isn't a template. The error
comes from:
/* Only certain kinds of names are allowed in constant
expression. Enumerators and template parameters have already
been handled above. */
if (! error_operand_p (decl)
&& integral_constant_expression_p
&& ! decl_constant_var_p (decl)
&& ! builtin_valid_in_constant_expr_p (decl))
{
if (!allow_non_integral_constant_expression_p)
{
error ("%qD cannot appear in a constant-expression", decl);
return error_mark_node;
}
in finish_id_expression, which is called by tsubst_copy_and_build, case
IDENTIFIER_NODE, with a false allow_non_integral_constant_expression_p.
What is puzzling me, is that, in the non-template struct z case,
finish_id_expression is called from cp_parser_primary_expression with a
true allow_non_integral_constant_expression_p and the error doesn't
occur. As a matter of fact, naively hacking the tsubst_copy_and_build
call to also pass true, mostly passes the testsuite, modulo a diagnostic
regression of template/nontype13.C.
Jason, basing on these few debugging notes, can you already see in which
direction I should further investigate?
Thanks,
Paolo.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] PR 50837
2011-11-10 0:33 [RFC] PR 50837 Paolo Carlini
@ 2011-11-10 1:54 ` Jason Merrill
2011-11-10 2:09 ` Paolo Carlini
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-11-10 1:54 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
On 11/09/2011 05:45 PM, Paolo Carlini wrote:
> finish_id_expression is called from cp_parser_primary_expression with a
> true allow_non_integral_constant_expression_p and the error doesn't
> occur.
Yes, allow_non_integral_constant_expression_p should always be true in
C++11.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] PR 50837
2011-11-10 1:54 ` Jason Merrill
@ 2011-11-10 2:09 ` Paolo Carlini
2011-11-10 3:58 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2011-11-10 2:09 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 983 bytes --]
On 11/10/2011 01:43 AM, Jason Merrill wrote:
> On 11/09/2011 05:45 PM, Paolo Carlini wrote:
>> finish_id_expression is called from cp_parser_primary_expression with a
>> true allow_non_integral_constant_expression_p and the error doesn't
>> occur.
>
> Yes, allow_non_integral_constant_expression_p should always be true in
> C++11.
Ah, good (sorry about the badly formatted code, by the way). Now, if I
apply the patchlet below, I get this error for template/nontype13.C:
nontype13.C:14:5: error: could not convert template argument
‘((Dummy<int>*)this)->Dummy<T>::evil<int>’ to ‘bool’
compared to the current:
nontype13.C:14:5: error: ‘void Dummy<T>::evil() [with T = int]’ cannot
appear in a constant-expression
Seems some sort of diagnostic quality regression...
By the way, before receiving your feedback, I was also wondering if the
tsubst_expr calls for STATIC_ASSERT should really pass true as
integral_constant_expression_p...
Paolo.
/////////////////////
[-- Attachment #2: p --]
[-- Type: text/plain, Size: 522 bytes --]
Index: pt.c
===================================================================
--- pt.c (revision 181246)
+++ pt.c (working copy)
@@ -13233,7 +13233,7 @@ tsubst_copy_and_build (tree t,
decl = finish_id_expression (t, decl, NULL_TREE,
&idk,
integral_constant_expression_p,
- /*allow_non_integral_constant_expression_p=*/false,
+ /*allow_non_integral_constant_expression_p=*/true,
&non_integral_constant_expression_p,
/*template_p=*/false,
/*done=*/true,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] PR 50837
2011-11-10 2:09 ` Paolo Carlini
@ 2011-11-10 3:58 ` Jason Merrill
2011-11-10 7:39 ` Paolo Carlini
0 siblings, 1 reply; 6+ messages in thread
From: Jason Merrill @ 2011-11-10 3:58 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
On 11/09/2011 07:56 PM, Paolo Carlini wrote:
> - /*allow_non_integral_constant_expression_p=*/false,
> + /*allow_non_integral_constant_expression_p=*/true,
This should be (cxx_dialect >= cxx0x) rather than true.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] PR 50837
2011-11-10 3:58 ` Jason Merrill
@ 2011-11-10 7:39 ` Paolo Carlini
2011-11-10 8:16 ` Jason Merrill
0 siblings, 1 reply; 6+ messages in thread
From: Paolo Carlini @ 2011-11-10 7:39 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 494 bytes --]
On 11/10/2011 02:12 AM, Jason Merrill wrote:
> On 11/09/2011 07:56 PM, Paolo Carlini wrote:
>> -
>> /*allow_non_integral_constant_expression_p=*/false,
>> + /*allow_non_integral_constant_expression_p=*/true,
>
> This should be (cxx_dialect >= cxx0x) rather than true.
Sure, we can do that (template/nontype13.C still has to be tweaked a bit
for the C++11 pass of testsuite). I'm finishing testing the below, Ok?
Thanks,
Paolo.
/////////////////////
[-- Attachment #2: CL_50837 --]
[-- Type: text/plain, Size: 377 bytes --]
/cp
2011-11-10 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50837
* pt.c (tsubst_copy_and_build) [IDENTIFIER_NODE]: In C++11 mode
pass allow_non_integral_constant_expression_p = true to
finish_id_expression.
/testsuite
2011-11-10 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/50837
* g++.dg/cpp0x/static_assert5.C: New.
* g++.dg/template/nontype13.C: Tweak.
[-- Attachment #3: patch_50837 --]
[-- Type: text/plain, Size: 1518 bytes --]
Index: testsuite/g++.dg/cpp0x/static_assert5.C
===================================================================
--- testsuite/g++.dg/cpp0x/static_assert5.C (revision 0)
+++ testsuite/g++.dg/cpp0x/static_assert5.C (revision 0)
@@ -0,0 +1,21 @@
+// PR c++/50837
+// { dg-options "-std=c++0x" }
+
+template<class T>
+struct z
+{
+ static constexpr bool test_constexpr()
+ {
+ return true;
+ }
+
+ static void test()
+ {
+ static_assert(test_constexpr(), "test1");
+ }
+};
+
+int main()
+{
+ z<int>::test();
+}
Index: testsuite/g++.dg/template/nontype13.C
===================================================================
--- testsuite/g++.dg/template/nontype13.C (revision 181246)
+++ testsuite/g++.dg/template/nontype13.C (working copy)
@@ -11,7 +11,7 @@ struct Dummy
template<bool B>
void tester()
{
- bar<evil>()(); // { dg-error "constant" }
+ bar<evil>()(); // { dg-error "constant|template" }
}
template<bool B>
struct bar
Index: cp/pt.c
===================================================================
--- cp/pt.c (revision 181247)
+++ cp/pt.c (working copy)
@@ -13233,7 +13233,7 @@ tsubst_copy_and_build (tree t,
decl = finish_id_expression (t, decl, NULL_TREE,
&idk,
integral_constant_expression_p,
- /*allow_non_integral_constant_expression_p=*/false,
+ /*allow_non_integral_constant_expression_p=*/(cxx_dialect >= cxx0x),
&non_integral_constant_expression_p,
/*template_p=*/false,
/*done=*/true,
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] PR 50837
2011-11-10 7:39 ` Paolo Carlini
@ 2011-11-10 8:16 ` Jason Merrill
0 siblings, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2011-11-10 8:16 UTC (permalink / raw)
To: Paolo Carlini; +Cc: gcc-patches
OK. And yes, we ought to fix that "cannot convert" error since often
that's not the problem.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-11-10 2:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-10 0:33 [RFC] PR 50837 Paolo Carlini
2011-11-10 1:54 ` Jason Merrill
2011-11-10 2:09 ` Paolo Carlini
2011-11-10 3:58 ` Jason Merrill
2011-11-10 7:39 ` Paolo Carlini
2011-11-10 8:16 ` Jason Merrill
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).