Fix compilation with Clang
authorJonathan Wakely <jwakely@redhat.com>
Fri, 25 Oct 2019 17:02:35 +0000 (18:02 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 25 Oct 2019 17:02:35 +0000 (18:02 +0100)
The new constexpr destructor on std::allocator breaks compilation with
Clang in C++2a mode. This only makes it constexpr if the compiler
supports the P0784R7 features.

* include/bits/allocator.h: Check __cpp_constexpr_dynamic_alloc
before making the std::allocator destructor constexpr.
* testsuite/20_util/allocator/requirements/constexpr.cc: New test.

From-SVN: r277458

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/allocator.h
libstdc++-v3/testsuite/20_util/allocator/requirements/constexpr.cc [new file with mode: 0644]

index d1f0e3a4cd439bc80f862f14969acca085488369..7997273a8578f4e689b013f9659aa567ebcdc8e1 100644 (file)
@@ -1,7 +1,12 @@
 2019-10-25  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/bits/allocator.h: Check __cpp_constexpr_dynamic_alloc
+       before making the std::allocator destructor constexpr.
+       * testsuite/20_util/allocator/requirements/constexpr.cc: New test.
+
        * include/bits/range_cmp.h: Check __cpp_lib_concepts before defining
        concepts. Fix comment.
+       * include/bits/allocator.h 
 
 2019-10-25  Gerald Pfeifer  <gerald@pfeifer.com>
 
index 2559c57b12eb0d91e2ca23e969a014c0a2fb9bf5..00d7461e42e8a2e44ffec9a34ff51183e42551f9 100644 (file)
@@ -160,7 +160,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        _GLIBCXX20_CONSTEXPR
        allocator(const allocator<_Tp1>&) _GLIBCXX_NOTHROW { }
 
-      _GLIBCXX20_CONSTEXPR
+#if __cpp_constexpr_dynamic_alloc
+      constexpr
+#endif
       ~allocator() _GLIBCXX_NOTHROW { }
 
 #if __cplusplus > 201703L
diff --git a/libstdc++-v3/testsuite/20_util/allocator/requirements/constexpr.cc b/libstdc++-v3/testsuite/20_util/allocator/requirements/constexpr.cc
new file mode 100644 (file)
index 0000000..6a6dbf1
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <memory>
+
+constexpr bool f()
+{
+  std::allocator<int> a;
+  return std::allocator_traits<std::allocator<int>>::max_size(a) > 0;
+}
+static_assert( f() );