PR c++/81852 define feature-test macro for -fthreadsafe-statics

Message ID 20170908200335.GA13166@redhat.com
State New
Headers show
Series
  • PR c++/81852 define feature-test macro for -fthreadsafe-statics
Related show

Commit Message

Jonathan Wakely Sept. 8, 2017, 8:03 p.m.
Define the __cpp_lib_threadsafe_static_init feature-test macro as per
recent SD-6 drafts.

Tested powerpc64le-linux and x86_64-linux.

OK for trunk?

The branches too?
commit 3ff1faeb36fad84f682f9b353152d450f8dfff92
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Sep 8 19:07:24 2017 +0100

    PR c++/81852 define feature-test macro for -fthreadsafe-statics
    
    gcc/c-family:
    
            PR c++/81852
            * c-cppbuiltin.c (c_cpp_builtins): Define __cpp_threadsafe_static_init.
    
    gcc/testsuite:
    
            PR c++/81852
            * g++.dg/cpp1y/feat-cxx11.C: Check __cpp_threadsafe_static_init.
            * g++.dg/cpp1y/feat-cxx14.C: Likewise.
            * g++.dg/cpp1y/feat-cxx98.C: Likewise.
            * g++.dg/cpp1y/feat-neg.C: Likewise.
            * g++.dg/cpp1z/feat-cxx1z.C: Likewise.

Comments

Jason Merrill Sept. 9, 2017, 8:33 a.m. | #1
On Fri, Sep 8, 2017 at 10:03 PM, Jonathan Wakely <jwakely@redhat.com> wrote:
> Define the __cpp_lib_threadsafe_static_init feature-test macro as per
> recent SD-6 drafts.
>
> Tested powerpc64le-linux and x86_64-linux.
>
> OK for trunk?
>
> The branches too?

Yes.

Jason
Jonathan Wakely Sept. 11, 2017, 5:21 p.m. | #2
On 09/09/17 10:33 +0200, Jason Merrill wrote:
>On Fri, Sep 8, 2017 at 10:03 PM, Jonathan Wakely <jwakely@redhat.com> wrote:
>> Define the __cpp_lib_threadsafe_static_init feature-test macro as per
>> recent SD-6 drafts.
>>
>> Tested powerpc64le-linux and x86_64-linux.
>>
>> OK for trunk?
>>
>> The branches too?
>
>Yes.
>
>Jason

I've committed this change to
https://gcc.gnu.org/projects/cxx-status.html documenting the new
macro.
Index: htdocs/projects/cxx-status.html
===================================================================
RCS file: /cvs/gcc/wwwdocs/htdocs/projects/cxx-status.html,v
retrieving revision 1.41
diff -u -r1.41 cxx-status.html
--- htdocs/projects/cxx-status.html	11 Apr 2017 22:28:24 -0000	1.41
+++ htdocs/projects/cxx-status.html	11 Sep 2017 17:19:49 -0000
@@ -866,7 +866,7 @@
       <td>Dynamic initialization and destruction with concurrency</td>
       <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2660.htm">N2660</a></td>
       <td><a href="../gcc-4.3/changes.html">GCC 4.3</a></td>
-      <td></td>
+      <td>__cpp_threadsafe_static_init >= 200806</td>
     </tr>
 
     <tr class="separator">

Patch

diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 8f377f698a6..4330c9102d9 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -987,6 +987,8 @@  c_cpp_builtins (cpp_reader *pfile)
 	}
       if (flag_new_ttp)
 	cpp_define (pfile, "__cpp_template_template_args=201611");
+      if (flag_threadsafe_statics)
+	cpp_define (pfile, "__cpp_threadsafe_static_init=200806");
     }
   /* Note that we define this for C as well, so that we know if
      __attribute__((cleanup)) will interface with EH.  */
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C
index 98112218d8f..b18fcfabad4 100644
--- a/gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C
@@ -125,6 +125,12 @@ 
 #  error "__cpp_alias_templates != 200704"
 #endif
 
+#ifndef __cpp_threadsafe_static_init
+#  error "__cpp_threadsafe_static_init"
+#elif __cpp_threadsafe_static_init != 200806
+#  error "__cpp_threadsafe_static_init != 200806"
+#endif
+
 //  C++14 features allowed in C++11 in non-ANSI modes:
 
 #ifndef __cpp_binary_literals
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
index 3b141ef67c4..412b9a33b8f 100644
--- a/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
@@ -118,6 +118,12 @@ 
 #  error "__cpp_alias_templates != 200704"
 #endif
 
+#ifndef __cpp_threadsafe_static_init
+#  error "__cpp_threadsafe_static_init"
+#elif __cpp_threadsafe_static_init != 200806
+#  error "__cpp_threadsafe_static_init != 200806"
+#endif
+
 //  C++14 features:
 
 #ifndef __cpp_binary_literals
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C
index d15e7aadcee..4db499cc2f4 100644
--- a/gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C
@@ -15,6 +15,14 @@ 
 #  error "__cpp_exceptions != 199711"
 #endif
 
+//  C++11 features allowed in C++98:
+
+#ifndef __cpp_threadsafe_static_init
+#  error "__cpp_threadsafe_static_init"
+#elif __cpp_threadsafe_static_init != 200806
+#  error "__cpp_threadsafe_static_init != 200806"
+#endif
+
 //  C++14 features allowed in C++98 in non-ANSI modes:
 
 #ifndef __cpp_binary_literals
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-neg.C b/gcc/testsuite/g++.dg/cpp1y/feat-neg.C
index 9f4a0412403..5e95418dfe4 100644
--- a/gcc/testsuite/g++.dg/cpp1y/feat-neg.C
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-neg.C
@@ -1,5 +1,5 @@ 
 // { dg-do compile }
-// { dg-options "-fno-rtti -fno-exceptions" }
+// { dg-options "-fno-rtti -fno-exceptions -fno-threadsafe-statics" }
 
 //  C++98 features with explicit opt-out:
 
@@ -10,3 +10,9 @@ 
 #ifndef __cpp_exceptions
 #  error "__cpp_exceptions" // { dg-error "error" }
 #endif
+
+//  C++11 features with explicit opt-out:
+
+#ifndef __cpp_threadsafe_static_init
+#  error "__cpp_threadsafe_static_init" // { dg-error "error" }
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
index e424e1c0ff0..a7c6cfe5169 100644
--- a/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
+++ b/gcc/testsuite/g++.dg/cpp1z/feat-cxx1z.C
@@ -106,6 +106,12 @@ 
 #  error "__cpp_alias_templates != 200704"
 #endif
 
+#ifndef __cpp_threadsafe_static_init
+#  error "__cpp_threadsafe_static_init"
+#elif __cpp_threadsafe_static_init != 200806
+#  error "__cpp_threadsafe_static_init != 200806"
+#endif
+
 //  C++14 features:
 
 #ifndef __cpp_binary_literals