}
\f
-/* Process a sizeof or alignof expression where the operand is a
- type. STD_ALIGNOF indicates whether an alignof has C++11 (minimum alignment)
- or GNU (preferred alignment) semantics; it is ignored if op is
+/* Process a sizeof or alignof expression where the operand is a type.
+ STD_ALIGNOF indicates whether an alignof has C++11 (minimum alignment)
+ or GNU (preferred alignment) semantics; it is ignored if OP is
SIZEOF_EXPR. */
tree
else
return error_mark_node;
}
+ else if (VOID_TYPE_P (type) && std_alignof)
+ {
+ if (complain)
+ error_at (loc, "invalid application of %qs to a void type",
+ OVL_OP_INFO (false, op)->name);
+ return error_mark_node;
+ }
bool dependent_p = dependent_type_p (type);
if (!dependent_p)
/* [dcl.align]/3:
When the alignment-specifier is of the form
- alignas(type-id ), it shall have the same effect as
- alignas(alignof(type-id )). */
+ alignas(type-id), it shall have the same effect as
+ alignas(alignof(type-id)). */
return cxx_sizeof_or_alignof_type (input_location,
- e, ALIGNOF_EXPR, true, false);
+ e, ALIGNOF_EXPR,
+ /*std_alignof=*/true,
+ /*complain=*/true);
/* If we reach this point, it means the alignas expression if of
the form "alignas(assignment-expression)", so we should follow
--- /dev/null
+// PR c++/104944
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wpedantic" }
+
+struct inc;
+
+struct alignas(inc) S1 { }; // { dg-error "invalid application" }
+struct alignas(void) S2 { }; // { dg-error "invalid application" }
+
+template <typename T>
+struct alignas(T) S4 {}; // { dg-error "invalid application" }
+
+template <typename T>
+struct alignas(T) S5 {}; // { dg-error "invalid application" }
+
+S4<void> s1;
+S5<inc> s2;
+
+void
+g ()
+{
+ auto s1 = alignof(void); // { dg-error "invalid application" }
+ auto s2 = alignof(const void); // { dg-error "invalid application" }
+ auto s3 = __alignof(void); // { dg-warning "invalid application" }
+ auto s4 = alignof(inc); // { dg-error "invalid application" }
+}