Fix noexcept merging with system headers.
authorJason Merrill <jason@redhat.com>
Tue, 3 Apr 2018 17:41:06 +0000 (13:41 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 3 Apr 2018 17:41:06 +0000 (13:41 -0400)
* typeck.c (merge_types): Limit matching attribute shortcut to
the default case.

From-SVN: r259042

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/noexcept-type19.h [new file with mode: 0644]

index ff3af265c95b9d7bcd6fc155d5a55fbb3e978490..405cf82b5d200b0e45b2151699244516f5b89db2 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-03  Jason Merrill  <jason@redhat.com>
+
+       * typeck.c (merge_types): Limit matching attribute shortcut to
+       the default case.
+
 2018-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/85147
index d454c6c5a2956c6dde1381d9c3b2e7a6b952641c..e33f2c34c7f9f49f8338e8b9d447547d5126319c 100644 (file)
@@ -899,14 +899,14 @@ merge_types (tree t1, tree t2)
       return t1;
 
     default:;
+      if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
+       return t1;
+      else if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
+       return t2;
+      break;
     }
 
-  if (attribute_list_equal (TYPE_ATTRIBUTES (t1), attributes))
-    return t1;
-  else if (attribute_list_equal (TYPE_ATTRIBUTES (t2), attributes))
-    return t2;
-  else
-    return cp_build_type_attribute_variant (t1, attributes);
+  return cp_build_type_attribute_variant (t1, attributes);
 }
 
 /* Return the ARRAY_TYPE type without its domain.  */
diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C b/gcc/testsuite/g++.dg/cpp1z/noexcept-type19.C
new file mode 100644 (file)
index 0000000..571c426
--- /dev/null
@@ -0,0 +1,14 @@
+// { dg-do compile { target c++11 } }
+
+#include "noexcept-type19.h"
+
+extern "C" void *malloc (size_t);
+
+template<class T> void f(T*);
+
+void *g(size_t);
+
+int main()
+{
+  f<decltype(malloc)>(g);
+}
diff --git a/gcc/testsuite/g++.dg/cpp1z/noexcept-type19.h b/gcc/testsuite/g++.dg/cpp1z/noexcept-type19.h
new file mode 100644 (file)
index 0000000..33a2935
--- /dev/null
@@ -0,0 +1,4 @@
+#pragma GCC system_header
+
+typedef decltype(sizeof(0)) size_t;
+extern "C" void *malloc (size_t) throw();