===================================================================
@@ -12252,6 +12252,12 @@ cp_parser_decltype_expr (cp_parser *parser,
/*declarator_p=*/false,
/*optional_p=*/false);
+ /* The production ~ class-name is not ok here, keep looking, it's probably
+ a complement expression (c++/65091). */
+ if (TREE_CODE (expr) == BIT_NOT_EXPR
+ && identifier_p (TREE_OPERAND (expr, 0)))
+ expr = error_mark_node;
+
if (!cp_parser_error_occurred (parser) && expr != error_mark_node)
{
bool non_integral_constant_expression_p = false;
===================================================================
@@ -0,0 +1,9 @@
+// PR c++/65091
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+auto foo(T x) -> decltype(~x)
+{ return ~x; }
+
+int bar()
+{ return foo(10); }