extern int comp_cv_qualification (int, int);
extern int comp_cv_qual_signature (tree, tree);
extern tree cxx_sizeof_or_alignof_expr (location_t, tree,
- enum tree_code, bool);
+ enum tree_code, bool, bool);
extern tree cxx_sizeof_or_alignof_type (location_t, tree,
enum tree_code, bool, bool);
extern tree cxx_alignas_expr (tree);
else
r = cxx_sizeof_or_alignof_expr (EXPR_LOCATION (t),
TREE_OPERAND (t, 0), SIZEOF_EXPR,
- false);
+ false, false);
if (r == error_mark_node)
r = size_one_node;
return r;
"ISO C++ does not allow %<alignof%> "
"with a non-type");
- ret = cxx_sizeof_or_alignof_expr (compound_loc,
- operand, op, true);
+ ret = cxx_sizeof_or_alignof_expr (compound_loc, operand, op,
+ std_alignof, true);
}
/* For SIZEOF_EXPR, just issue diagnostics, but keep
SIZEOF_EXPR with the original operand. */
else
return cxx_sizeof_or_alignof_expr (input_location,
expanded, SIZEOF_EXPR,
+ false,
complain & tf_error);
}
else
complain & tf_error);
else
r = cxx_sizeof_or_alignof_expr (input_location,
- op1, TREE_CODE (t),
+ op1, TREE_CODE (t), std_alignof,
complain & tf_error);
if (TREE_CODE (t) == SIZEOF_EXPR && r != error_mark_node)
{
/* Implement the __alignof keyword: Return the minimum required
alignment of E, measured in bytes. For VAR_DECL's and
FIELD_DECL's return DECL_ALIGN (which can be set from an
- "aligned" __attribute__ specification). */
+ "aligned" __attribute__ specification). STD_ALIGNOF acts
+ like in cxx_sizeof_or_alignof_type. */
static tree
-cxx_alignof_expr (location_t loc, tree e, tsubst_flags_t complain)
+cxx_alignof_expr (location_t loc, tree e, bool std_alignof,
+ tsubst_flags_t complain)
{
tree t;
TREE_SIDE_EFFECTS (e) = 0;
TREE_READONLY (e) = 1;
SET_EXPR_LOCATION (e, loc);
+ ALIGNOF_EXPR_STD_P (e) = std_alignof;
return e;
}
}
else
return cxx_sizeof_or_alignof_type (loc, TREE_TYPE (e),
- ALIGNOF_EXPR, false,
+ ALIGNOF_EXPR, std_alignof,
complain & tf_error);
return fold_convert_loc (loc, size_type_node, t);
}
/* Process a sizeof or alignof expression E with code OP where the operand
- is an expression. */
+ is an expression. STD_ALIGNOF acts like in cxx_sizeof_or_alignof_type. */
tree
cxx_sizeof_or_alignof_expr (location_t loc, tree e, enum tree_code op,
- bool complain)
+ bool std_alignof, bool complain)
{
+ gcc_assert (op == SIZEOF_EXPR || op == ALIGNOF_EXPR);
if (op == SIZEOF_EXPR)
return cxx_sizeof_expr (loc, e, complain? tf_warning_or_error : tf_none);
else
- return cxx_alignof_expr (loc, e, complain? tf_warning_or_error : tf_none);
+ return cxx_alignof_expr (loc, e, std_alignof,
+ complain? tf_warning_or_error : tf_none);
}
/* Build a representation of an expression 'alignas(E).' Return the
--- /dev/null
+// PR c++/88115
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-Wno-pedantic" }
+
+// Verify the non-standard extension alignof(expr) behaves like
+// alignof(type) to yield the ABI alignment of the type, and that
+// __alignof__(expr) behaves like __alignof__(type) to yield the
+// preferred alignment of the type.
+
+static_assert(alignof(double{}) == alignof(double), "");
+static_assert(__alignof__(double{}) == __alignof__(double), "");
+
+template <class T>
+void f() {
+ static_assert(alignof(T{}) == alignof(T), "");
+ static_assert(__alignof__(T{}) == __alignof__(T), "");
+}
+
+template void f<double>();
case SIZEOF_EXPR:
case ALIGNOF_EXPR:
result = cxx_sizeof_or_alignof_expr (input_location,
- op0, opcode, true);
+ op0, opcode, true, true);
break;
case DELETE_EXPR: