diff mbox

[C++] PR 79380

Message ID 7f868ae5-ed33-75e4-9093-858580f33d82@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Feb. 17, 2017, 1:28 p.m. UTC
Hi,

this ICE on invalid seems quite similar to c++/69637 which I fixed 
recently: we again end up with an unhandled OVERLOAD in the main 
cxx_eval_constant_expression switch and in this case we don't diagnose 
at all the invalid input. Thus, I propose to add a check to 
cxx_alignas_expr completely similar to what we have in grokbitfield on 
the width. Tested x86_64-linux.

Thanks, Paolo.

PS: I think we are moving away from pretty printing (%qE) expressions, 
thus I dind't try in the patchlet to print the argument, only its 
(wrong) type.

//////////////////////
/cp
2017-02-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/79380
	* typeck.c (cxx_alignas_expr): Reject a non-integral alignas
	argument.

/testsuite
2017-02-17  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/79380
	* g++.dg/cpp0x/alignas8.C: New.
diff mbox

Patch

Index: cp/typeck.c
===================================================================
--- cp/typeck.c	(revision 245503)
+++ cp/typeck.c	(working copy)
@@ -1795,6 +1795,12 @@  cxx_alignas_expr (tree e)
 
          the assignment-expression shall be an integral constant
 	 expression.  */
+
+  if (!INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (e)))
+    {
+      error ("%<alignas%> argument has non-integral type %qT", TREE_TYPE (e));
+      return error_mark_node;
+    }
   
   return cxx_constant_value (e);
 }
Index: testsuite/g++.dg/cpp0x/alignas8.C
===================================================================
--- testsuite/g++.dg/cpp0x/alignas8.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/alignas8.C	(working copy)
@@ -0,0 +1,7 @@ 
+// PR c++/79380
+// { dg-do compile { target c++11 } }
+
+template < typename > constexpr int f () {  return 8;  }
+
+// should have been: struct alignas (f<int>()) S {};
+struct alignas (f) S {};  // { dg-error "17:'alignas' argument has non-integral type" }