I admit I haven't spent much time on this, but it seems we should just check whether we can set the expr location before actually setting it...
Regtested/bootstrapped on x86_64-linux, ok for trunk? 2013-09-24 Marek Polacek <pola...@redhat.com> PR c++/58516 cp/ * semantics.c (finish_transaction_stmt): Set location only when the expression can have location. testsuite/ * g++.dg/tm/pr58516.C: New test. --- gcc/cp/semantics.c.mp 2013-09-24 17:24:59.907548551 +0200 +++ gcc/cp/semantics.c 2013-09-24 17:25:04.251564960 +0200 @@ -5199,7 +5199,9 @@ finish_transaction_stmt (tree stmt, tree { tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt), noex); - SET_EXPR_LOCATION (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt))); + /* This may occur when the STATEMENT_LIST is empty. */ + if (CAN_HAVE_LOCATION_P (body)) + SET_EXPR_LOCATION (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt))); TREE_SIDE_EFFECTS (body) = 1; TRANSACTION_EXPR_BODY (stmt) = body; } --- gcc/testsuite/g++.dg/tm/pr58516.C.mp 2013-09-24 17:27:08.859055542 +0200 +++ gcc/testsuite/g++.dg/tm/pr58516.C 2013-09-24 17:28:29.829354635 +0200 @@ -0,0 +1,7 @@ +// { dg-do compile } +// { dg-options "-std=c++0x -fgnu-tm" } + +void foo() +{ + __transaction_atomic noexcept(false) {} +} Marek