c++: Sorry about type-dependent arg for __builtin_has_attribute [PR90915]
authorMarek Polacek <polacek@redhat.com>
Fri, 8 May 2020 01:10:42 +0000 (21:10 -0400)
committerMarek Polacek <polacek@redhat.com>
Mon, 18 May 2020 22:07:18 +0000 (18:07 -0400)
Until 92104 is fixed, let's sorry rather than crash.

PR c++/90915
* parser.c (cp_parser_has_attribute_expression): Sorry on a
type-dependent argument.

* g++.dg/ext/builtin-has-attribute.C: New test.

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/builtin-has-attribute.C [new file with mode: 0644]

index 52422cef10f732d3079b50a6b0fb18a2e8ea27e1..d8ad1d63bd41e491d9efee02bb50a8e88f4a7a85 100644 (file)
@@ -1,3 +1,9 @@
+2020-05-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/90915
+       * parser.c (cp_parser_has_attribute_expression): Sorry on a
+       type-dependent argument.
+
 2020-05-18  Marek Polacek  <polacek@redhat.com>
 
        DR 1512
index 41712bfdc2cd149638d932e1b89ac58bbb4926f5..e944841f5a34467cc264ee6aee7e2c7a48984ac7 100644 (file)
@@ -8679,7 +8679,12 @@ cp_parser_has_attribute_expression (cp_parser *parser)
   location_t atloc = cp_lexer_peek_token (parser->lexer)->location;
   if (tree attr = cp_parser_gnu_attribute_list (parser, /*exactly_one=*/true))
     {
-      if (oper != error_mark_node)
+      if (oper == error_mark_node)
+       /* Nothing.  */;
+      else if (type_dependent_expression_p (oper))
+       sorry_at (atloc, "%<__builtin_has_attribute%> with dependent argument "
+                 "not supported yet");
+      else
        {
          /* Fold constant expressions used in attributes first.  */
          cp_check_const_attributes (attr);
index 453e581a3facbb922720c94c159c48b0bb28bf54..67e9394ed92f09e707af2233216937fec41f6354 100644 (file)
@@ -1,3 +1,8 @@
+2020-05-18  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/90915
+       * g++.dg/ext/builtin-has-attribute.C: New test.
+
 2020-05-18  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/92815
diff --git a/gcc/testsuite/g++.dg/ext/builtin-has-attribute.C b/gcc/testsuite/g++.dg/ext/builtin-has-attribute.C
new file mode 100644 (file)
index 0000000..3438dd5
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/90915
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+void foo ()
+{
+  static_assert(!__builtin_has_attribute(T::a, aligned), ""); // { dg-message "sorry, unimplemented: .__builtin_has_attribute. with dependent argument not supported yet" }
+}