aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorEdward Smith-Rowland <3dw4rd@verizon.net>2014-10-01 11:49:23 +0000
committerEdward Smith-Rowland <emsr@gcc.gnu.org>2014-10-01 11:49:23 +0000
commita15f7cb8b8c124bb7c49ab9b8d29dfd62ea58d10 (patch)
tree0305f88949de10054e322e52911e9a53306c454d /gcc
parent5fbb36f4a4e85956c241dafe603f1fc1be10472e (diff)
downloadgcc-a15f7cb8b8c124bb7c49ab9b8d29dfd62ea58d10.zip
gcc-a15f7cb8b8c124bb7c49ab9b8d29dfd62ea58d10.tar.gz
gcc-a15f7cb8b8c124bb7c49ab9b8d29dfd62ea58d10.tar.bz2
Implement SD-6: SG10 Feature Test Recommendations
2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * internal.h (lexer_state, spec_nodes): Add in__has_include__. * directives.c: Support __has_include__ builtin. * expr.c (parse_has_include): New function to parse __has_include__ builtin; (eval_token()): Use it. * files.c (_cpp_has_header()): New funtion to look for header; (open_file_failed()): Not an error to not find a header file for __has_include__. * identifiers.c (_cpp_init_hashtable()): Add entry for __has_include__. * pch.c (cpp_read_state): Lookup __has_include__. * traditional.c (enum ls, _cpp_scan_out_logical_line()): Walk through __has_include__ statements. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * c-cppbuiltin.c (c_cpp_builtins()): Define language feature macros and the __has_header macro. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * include/bits/basic_string.h: Add __cpp_lib feature test macro. * include/bits/stl_algobase.h: Ditto. * include/bits/stl_function.h: Ditto. * include/bits/unique_ptr.h: Ditto. * include/std/chrono: Ditto. * include/std/complex: Ditto. * include/std/iomanip: Ditto. * include/std/shared_mutex: Ditto. * include/std/tuple: Ditto. * include/std/type_traits: Ditto. * include/std/utility: Ditto. * testsuite/experimental/feat-cxx14.cc: New. * testsuite/experimental/feat-lib-fund.cc: New. * testsuite/20_util/declval/requirements/1_neg.cc: Adjust. * testsuite/20_util/duration/literals/range.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg2.cc: Adjust. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Adjust. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Adjust. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Adjust. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust. * testsuite/23_containers/array/tuple_interface/tuple_element_neg.cc: Adjust. 2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net> Implement SD-6: SG10 Feature Test Recommendations * g++.dg/cpp1y/feat-cxx11-neg.C: New. * g++.dg/cpp1y/feat-cxx11.C: New. * g++.dg/cpp1y/feat-cxx14.C: New. * g++.dg/cpp1y/feat-cxx98.C: New. * g++.dg/cpp1y/feat-cxx98-neg.C: New. * g++.dg/cpp1y/phoobhar.h: New. * g++.dg/cpp1y/testinc/phoobhar.h: New. From-SVN: r215752
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-cppbuiltin.c48
-rw-r--r--gcc/testsuite/ChangeLog11
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C40
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C81
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C232
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C6
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C9
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/phoobhar.h16
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/testinc/phoobhar.h0
10 files changed, 449 insertions, 0 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index b3a7131..fef201b 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net>
+
+ Implement SD-6: SG10 Feature Test Recommendations
+ * c-cppbuiltin.c (c_cpp_builtins()): Define language feature
+ macros and the __has_header macro.
+
2014-09-30 Jason Merrill <jason@redhat.com>
* c-common.h (enum rid): Add RID_IS_TRIVIALLY_ASSIGNABLE and
diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
index 6748db4..b6ac0b0 100644
--- a/gcc/c-family/c-cppbuiltin.c
+++ b/gcc/c-family/c-cppbuiltin.c
@@ -787,18 +787,66 @@ c_cpp_builtins (cpp_reader *pfile)
/* For stddef.h. They require macros defined in c-common.c. */
c_stddef_cpp_builtins ();
+ /* Set include test macros for all C/C++ (not for just C++11 etc.)
+ the builtins __has_include__ and __has_include_next__ are defined
+ in libcpp. */
+ cpp_define (pfile, "__has_include(STR)=__has_include__(STR)");
+ cpp_define (pfile, "__has_include_next(STR)=__has_include_next__(STR)");
+
if (c_dialect_cxx ())
{
if (flag_weak && SUPPORTS_ONE_ONLY)
cpp_define (pfile, "__GXX_WEAK__=1");
else
cpp_define (pfile, "__GXX_WEAK__=0");
+
if (warn_deprecated)
cpp_define (pfile, "__DEPRECATED");
+
if (flag_rtti)
cpp_define (pfile, "__GXX_RTTI");
+
if (cxx_dialect >= cxx11)
cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
+
+ /* Binary literals have been allowed in g++ before C++11
+ and were standardized for C++14. */
+ if (!pedantic || cxx_dialect > cxx11)
+ cpp_define (pfile, "__cpp_binary_literals=201304");
+ if (cxx_dialect >= cxx11)
+ {
+ /* Set feature test macros for C++11 */
+ cpp_define (pfile, "__cpp_unicode_characters=200704");
+ cpp_define (pfile, "__cpp_raw_strings=200710");
+ cpp_define (pfile, "__cpp_unicode_literals=200710");
+ cpp_define (pfile, "__cpp_user_defined_literals=200809");
+ cpp_define (pfile, "__cpp_lambdas=200907");
+ cpp_define (pfile, "__cpp_constexpr=200704");
+ cpp_define (pfile, "__cpp_static_assert=200410");
+ cpp_define (pfile, "__cpp_decltype=200707");
+ cpp_define (pfile, "__cpp_attributes=200809");
+ cpp_define (pfile, "__cpp_rvalue_reference=200610");
+ cpp_define (pfile, "__cpp_variadic_templates=200704");
+ cpp_define (pfile, "__cpp_alias_templates=200704");
+ }
+ if (cxx_dialect > cxx11)
+ {
+ /* Set feature test macros for C++14 */
+ cpp_define (pfile, "__cpp_return_type_deduction=201304");
+ cpp_define (pfile, "__cpp_init_captures=201304");
+ cpp_define (pfile, "__cpp_generic_lambdas=201304");
+ //cpp_undef (pfile, "__cpp_constexpr");
+ //cpp_define (pfile, "__cpp_constexpr=201304");
+ cpp_define (pfile, "__cpp_decltype_auto=201304");
+ //cpp_define (pfile, "__cpp_aggregate_nsdmi=201304");
+ cpp_define (pfile, "__cpp_variable_templates=201304");
+ cpp_define (pfile, "__cpp_digit_separators=201309");
+ cpp_define (pfile, "__cpp_attribute_deprecated=201309");
+ //cpp_define (pfile, "__cpp_sized_deallocation=201309");
+ /* We'll have to see where runtime arrays wind up.
+ Let's put it in C++14 for now. */
+ cpp_define (pfile, "__cpp_runtime_arrays=201304");
+ }
}
/* 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/ChangeLog b/gcc/testsuite/ChangeLog
index 2ccb1d9..b07bb66 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,14 @@
+2014-10-01 Edward Smith-Rowland <3dw4rd@verizon.net>
+
+ Implement SD-6: SG10 Feature Test Recommendations
+ * g++.dg/cpp1y/feat-cxx11-neg.C: New.
+ * g++.dg/cpp1y/feat-cxx11.C: New.
+ * g++.dg/cpp1y/feat-cxx14.C: New.
+ * g++.dg/cpp1y/feat-cxx98.C: New.
+ * g++.dg/cpp1y/feat-cxx98-neg.C: New.
+ * g++.dg/cpp1y/phoobhar.h: New.
+ * g++.dg/cpp1y/testinc/phoobhar.h: New.
+
2014-09-30 Teresa Johnson <tejohnson@google.com>
* gcc.dg/tree-prof/20050826-2.c: New test.
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C
new file mode 100644
index 0000000..8719577
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx11-neg.C
@@ -0,0 +1,40 @@
+// { dg-do compile { target c++11_only } }
+// { dg-options "-pedantic-errors" }
+
+// These *are* defined in C++14 onwards.
+
+#ifndef __cpp_binary_literals
+# error "__cpp_binary_literals" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_init_captures
+# error "__cpp_init_captures" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_generic_lambdas
+# error "__cpp_generic_lambdas" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_decltype_auto
+# error "__cpp_decltype_auto" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_return_type_deduction
+# error "__cpp_return_type_deduction" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_variable_templates
+# error "__cpp_variable_templates" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_digit_separators
+# error "__cpp_digit_separators" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_attribute_deprecated
+# error "__cpp_attribute_deprecated" // { dg-error "error" }
+#endif
+
+#ifndef __cpp_runtime_arrays
+# error "__cpp_runtime_arrays" // { dg-error "error" }
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C
new file mode 100644
index 0000000..606a5ce
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx11.C
@@ -0,0 +1,81 @@
+// { dg-do compile }
+// { dg-options "-std=gnu++11" }
+
+#ifndef __cpp_unicode_characters
+# error "__cpp_unicode_characters"
+#elif __cpp_unicode_characters != 200704
+# error "__cpp_unicode_characters != 200704"
+#endif
+
+#ifndef __cpp_raw_strings
+# error "__cpp_raw_strings"
+#elif __cpp_raw_strings != 200710
+# error "__cpp_raw_strings != 200710"
+#endif
+
+#ifndef __cpp_unicode_literals
+# error "__cpp_unicode_literals"
+#elif __cpp_unicode_literals != 200710
+# error "__cpp_unicode_literals != 200710"
+#endif
+
+#ifndef __cpp_user_defined_literals
+# error "__cpp_user_defined_literals"
+#elif __cpp_user_defined_literals != 200809
+# error "__cpp_user_defined_literals != 200809"
+#endif
+
+#ifndef __cpp_lambdas
+# error "__cpp_lambdas"
+#elif __cpp_lambdas != 200907
+# error "__cpp_lambdas != 200907"
+#endif
+
+#ifndef __cpp_constexpr
+# error "__cpp_constexpr"
+#elif __cpp_constexpr != 200704
+# error "__cpp_constexpr != 200704"
+#endif
+
+#ifndef __cpp_static_assert
+# error "__cpp_static_assert"
+#elif __cpp_static_assert != 200410
+# error "__cpp_static_assert != 200410"
+#endif
+
+#ifndef __cpp_decltype
+# error "__cpp_decltype"
+#elif __cpp_decltype != 200707
+# error "__cpp_decltype != 200707"
+#endif
+
+#ifndef __cpp_attributes
+# error "__cpp_attributes"
+#elif __cpp_attributes != 200809
+# error "__cpp_attributes != 200809"
+#endif
+
+#ifndef __cpp_rvalue_reference
+# error "__cpp_rvalue_reference"
+#elif __cpp_rvalue_reference != 200610
+# error "__cpp_rvalue_reference != 200610"
+#endif
+
+#ifndef __cpp_variadic_templates
+# error "__cpp_variadic_templates"
+#elif __cpp_variadic_templates != 200704
+# error "__cpp_variadic_templates != 200704"
+#endif
+
+#ifndef __cpp_alias_templates
+# error "__cpp_alias_templates"
+#elif __cpp_alias_templates != 200704
+# error "__cpp_alias_templates != 200704"
+#endif
+
+// These C++14 features are allowed in C++11 in non-ANSI modes.
+#ifndef __cpp_binary_literals
+# error "__cpp_binary_literals"
+#elif __cpp_binary_literals != 201304
+# error "__cpp_binary_literals != 201304"
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
new file mode 100644
index 0000000..18ff098
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx14.C
@@ -0,0 +1,232 @@
+// { dg-do compile { target c++14 } }
+// { dg-options "-I${srcdir}/g++.dg/cpp1y -I${srcdir}/g++.dg/cpp1y/testinc" }
+
+// Begin C++11 tests.
+
+#ifndef __cpp_unicode_characters
+# error "__cpp_unicode_characters"
+#elif __cpp_unicode_characters != 200704
+# error "__cpp_unicode_characters != 200704"
+#endif
+
+#ifndef __cpp_raw_strings
+# error "__cpp_raw_strings"
+#elif __cpp_raw_strings != 200710
+# error "__cpp_raw_strings != 200710"
+#endif
+
+#ifndef __cpp_unicode_literals
+# error "__cpp_unicode_literals"
+#elif __cpp_unicode_literals != 200710
+# error "__cpp_unicode_literals != 200710"
+#endif
+
+#ifndef __cpp_user_defined_literals
+# error "__cpp_user_defined_literals"
+#elif __cpp_user_defined_literals != 200809
+# error "__cpp_user_defined_literals != 200809"
+#endif
+
+#ifndef __cpp_lambdas
+# error "__cpp_lambdas"
+#elif __cpp_lambdas != 200907
+# error "__cpp_lambdas != 200907"
+#endif
+
+#ifndef __cpp_constexpr
+# error "__cpp_constexpr"
+#elif __cpp_constexpr != 200704
+# error "__cpp_constexpr != 200704"
+#endif
+
+#ifndef __cpp_static_assert
+# error "__cpp_static_assert"
+#elif __cpp_static_assert != 200410
+# error "__cpp_static_assert != 200410"
+#endif
+
+#ifndef __cpp_decltype
+# error "__cpp_decltype"
+#elif __cpp_decltype != 200707
+# error "__cpp_decltype != 200707"
+#endif
+
+#ifndef __cpp_attributes
+# error "__cpp_attributes"
+#elif __cpp_attributes != 200809
+# error "__cpp_attributes != 200809"
+#endif
+
+#ifndef __cpp_rvalue_reference
+# error "__cpp_rvalue_reference"
+#elif __cpp_rvalue_reference != 200610
+# error "__cpp_rvalue_reference != 200610"
+#endif
+
+#ifndef __cpp_variadic_templates
+# error "__cpp_variadic_templates"
+#elif __cpp_variadic_templates != 200704
+# error "__cpp_variadic_templates != 200704"
+#endif
+
+#ifndef __cpp_alias_templates
+# error "__cpp_alias_templates"
+#elif __cpp_alias_templates != 200704
+# error "__cpp_alias_templates != 200704"
+#endif
+
+// Begin C++14 tests.
+
+#ifndef __cpp_binary_literals
+# error "__cpp_binary_literals"
+#elif __cpp_binary_literals != 201304
+# error "__cpp_binary_literals != 201304"
+#endif
+
+#ifndef __cpp_init_captures
+# error "__cpp_init_captures"
+#elif __cpp_init_captures != 201304
+# error "__cpp_init_captures != 201304"
+#endif
+
+#ifndef __cpp_generic_lambdas
+# error "__cpp_generic_lambdas"
+#elif __cpp_generic_lambdas != 201304
+# error "__cpp_generic_lambdas != 201304"
+#endif
+
+// TODO: Change 200704 to 201304 when C++14 constexpr goes in.
+#ifndef __cpp_constexpr
+# error "__cpp_constexpr"
+#elif __cpp_constexpr != 200704
+# error "__cpp_constexpr != 200704"
+#endif
+
+#ifndef __cpp_decltype_auto
+# error "__cpp_decltype_auto"
+#elif __cpp_decltype_auto != 201304
+# error "__cpp_decltype_auto != 201304"
+#endif
+
+#ifndef __cpp_return_type_deduction
+# error "__cpp_return_type_deduction"
+#elif __cpp_return_type_deduction != 201304
+# error "__cpp_return_type_deduction != 201304"
+#endif
+
+#ifndef __cpp_runtime_arrays
+# error "__cpp_runtime_arrays"
+#elif __cpp_runtime_arrays != 201304
+# error "__cpp_runtime_arrays != 201304"
+#endif
+
+// Aggregate initializers not in yet.
+#ifdef __cpp_aggregate_nsdmi
+# error "__cpp_aggregate_nsdmi"
+#endif
+
+#ifndef __cpp_variable_templates
+# error "__cpp_variable_templates"
+#elif __cpp_variable_templates != 201304
+# error "__cpp_variable_templates != 201304"
+#endif
+
+#ifndef __cpp_digit_separators
+# error "__cpp_digit_separators"
+#elif __cpp_digit_separators != 201309
+# error "__cpp_digit_separators != 201309"
+#endif
+
+#ifndef __cpp_attribute_deprecated
+# error "__cpp_attribute_deprecated"
+#elif __cpp_attribute_deprecated != 201309
+# error "__cpp_attribute_deprecated != 201309"
+#endif
+
+// Sized deallocation not in yet.
+#ifdef __cpp_sized_deallocation
+# error "__cpp_sized_deallocation"
+#endif
+
+// Begin include checks.
+
+// Check for __has_include macro.
+#ifndef __has_include
+# error "__has_include"
+#endif
+
+// Quoted complex.h should find at least the bracket version (use operator).
+#if __has_include__ "complex.h"
+#else
+# error "complex.h"
+#endif
+
+// Try known bracket header (use operator).
+#if __has_include__(<complex>)
+#else
+# error "<complex>"
+#endif
+
+// Define and use a macro to invoke the operator.
+#define sluggo(TXT) __has_include__(TXT)
+
+#if sluggo(<complex>)
+#else
+# error "<complex>"
+#endif
+
+#if ! sluggo(<complex>)
+# error "<complex>"
+#else
+#endif
+
+// Quoted complex.h should find at least the bracket version.
+#if __has_include("complex.h")
+#else
+# error "complex.h"
+#endif
+
+// Try known local quote header.
+#if __has_include("complex_literals.h")
+#else
+# error "\"complex_literals.h\""
+#endif
+
+// Try nonexistent bracket header.
+#if __has_include(<stuff>)
+# error "<stuff>"
+#else
+#endif
+
+// Try nonexistent quote header.
+#if __has_include("phlegm")
+# error "\"phlegm\""
+#else
+#endif
+
+// Test __has_include_next.
+#if __has_include("phoobhar.h")
+# include "phoobhar.h"
+#else
+# error "__has_include(\"phoobhar.h\")"
+#endif
+
+// Try a macro.
+#define COMPLEX_INC "complex.h"
+#if __has_include(COMPLEX_INC)
+#else
+# error COMPLEX_INC
+#endif
+
+// Realistic use of __has_include.
+#if __has_include(<array>)
+# define STD_ARRAY 1
+# include <array>
+ template<typename _Tp, size_t _Num>
+ using array = std::array<_Tp, _Num>;
+#elif __has_include(<tr1/array>)
+# define TR1_ARRAY 1
+# include <tr1/array>
+ template<typename _Tp, size_t _Num>
+ typedef std::tr1::array<_Tp, _Num> array;
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C
new file mode 100644
index 0000000..db019f2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx98-neg.C
@@ -0,0 +1,6 @@
+// { dg-do compile { target c++98_only } }
+// { dg-options "-ansi" }
+
+#ifdef __cpp_runtime_arrays
+# error "__cpp_runtime_arrays" // { dg-error "error" }
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C b/gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C
new file mode 100644
index 0000000..a0a2b75
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/feat-cxx98.C
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++98_only } }
+// { dg-options "" }
+
+// These C++14 features are allowed in C++98 in non-ANSI modes.
+#ifndef __cpp_binary_literals
+# error "__cpp_binary_literals"
+#elif __cpp_binary_literals != 201304
+# error "__cpp_binary_literals != 201304"
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1y/phoobhar.h b/gcc/testsuite/g++.dg/cpp1y/phoobhar.h
new file mode 100644
index 0000000..7feec36
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/phoobhar.h
@@ -0,0 +1,16 @@
+
+int
+phoo();
+
+int
+bhar();
+
+#ifndef __has_include_next
+# error "__has_include_next"
+#else
+# if __has_include_next("phoobhar.h")
+# include_next "phoobhar.h"
+# else
+# error "__has_include_next(\"phoobhar.h\")"
+# endif
+#endif
diff --git a/gcc/testsuite/g++.dg/cpp1y/testinc/phoobhar.h b/gcc/testsuite/g++.dg/cpp1y/testinc/phoobhar.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/testinc/phoobhar.h