@@ -106,7 +106,9 @@ typedef enum non_integral_constant {
/* a comma operator */
NIC_COMMA,
/* a call to a constructor */
- NIC_CONSTRUCTOR
+ NIC_CONSTRUCTOR,
+ /* a transaction expression */
+ NIC_TRANSACTION
} non_integral_constant;
/* The various kinds of errors about name-lookup failing. */
@@ -2682,6 +2684,10 @@ cp_parser_non_integral_constant_expression (cp_parser *parser,
error ("a call to a constructor "
"cannot appear in a constant-expression");
return true;
+ case NIC_TRANSACTION:
+ error ("a transaction expression "
+ "cannot appear in a constant-expression");
+ return true;
case NIC_THIS:
msg = "this";
break;
@@ -26656,6 +26662,14 @@ cp_parser_transaction_expression (cp_parser *parser, enum rid keyword)
gcc_assert (keyword == RID_TRANSACTION_ATOMIC
|| keyword == RID_TRANSACTION_RELAXED);
+
+ if (!flag_tm)
+ error (keyword == RID_TRANSACTION_RELAXED
+ ? "%<__transaction_relaxed%> without transactional memory "
+ "support enabled"
+ : "%<__transaction_atomic%> without transactional memory "
+ "support enabled");
+
token = cp_parser_require_keyword (parser, keyword,
(keyword == RID_TRANSACTION_ATOMIC ? RT_TRANSACTION_ATOMIC
: RT_TRANSACTION_RELAXED));
@@ -26680,7 +26694,10 @@ cp_parser_transaction_expression (cp_parser *parser, enum rid keyword)
}
parser->in_transaction = old_in;
- return ret;
+ if (cp_parser_non_integral_constant_expression (parser, NIC_TRANSACTION))
+ return error_mark_node;
+
+ return (flag_tm ? ret : error_mark_node);
}
/* Parse a function-transaction-block.
@@ -8140,6 +8140,7 @@ potential_constant_expression_1 (tree t, bool want_rval, tsubst_flags_t flags)
case STMT_EXPR:
case EXPR_STMT:
case BIND_EXPR:
+ case TRANSACTION_EXPR:
if (flags & tf_error)
error ("expression %qE is not a constant-expression", t);
return false;
new file mode 100644
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* Make sure that we don't just crash without -fgnu-tm enabled. */
+/* { dg-options "" } */
+
+int x;
+
+int foo(void)
+{
+ return __transaction_atomic (x + 1); /* { dg-error "" } */
+}
+
+int bar(void)
+{
+ return __transaction_relaxed (x + 1); /* { dg-error "" } */
+}