Skip to content
Snippets Groups Projects
  • Marek Polacek's avatar
    5388a43f
    c++: Add support for -std={c,gnu}++2{c,6} · 5388a43f
    Marek Polacek authored
    It seems prudent to add C++26 now that the first C++26 papers have been
    approved.  I followed commit r11-6920 as well as r8-3237.
    
    Since C++23 is essentially finished and its __cplusplus value has
    settled to 202302L, I've updated cpp_init_builtins and marked
    -std=c++2b Undocumented and made -std=c++23 no longer Undocumented.
    
    As for __cplusplus, I've chosen 202400L:
    
      $ xg++ -std=c++26 -dM -E -x c++ - < /dev/null | grep cplusplus
      #define __cplusplus 202400L
    
    I've verified the patch with a simple test, exercising the new
    directives.  Don't forget to update your GXX_TESTSUITE_STDS!
    
    This patch does not add -Wc++26-extensions.
    
    gcc/c-family/ChangeLog:
    
    	* c-common.h (cxx_dialect): Add cxx26 as a dialect.
    	* c-opts.cc (set_std_cxx26): New.
    	(c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is
    	enabled.
    	(c_common_post_options): Adjust comments.
    	* c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26,
    	and -std=gnu++2c.
    	(std=c++2b): Mark as Undocumented.
    	(std=c++23): No longer Undocumented.
    
    gcc/ChangeLog:
    
    	* doc/cpp.texi (__cplusplus): Document value for -std=c++26 and
    	-std=gnu++26.  Document that for C++23, its value is 202302L.
    	* doc/invoke.texi: Document -std=c++26 and -std=gnu++26.
    	* dwarf2out.cc (highest_c_language): Handle GNU C++26.
    	(gen_compile_unit_die): Likewise.
    
    libcpp/ChangeLog:
    
    	* include/cpplib.h (c_lang): Add CXX26 and GNUCXX26.
    	* init.cc (lang_defaults): Add rows for CXX26 and GNUCXX26.
    	(cpp_init_builtins): Set __cplusplus to 202400L for C++26.
    	Set __cplusplus to 202302L for C++23.
    
    gcc/testsuite/ChangeLog:
    
    	* lib/target-supports.exp (check_effective_target_c++23): Return
    	1 also if check_effective_target_c++26.
    	(check_effective_target_c++23_down): New.
    	(check_effective_target_c++26_only): New.
    	(check_effective_target_c++26): New.
    	* g++.dg/cpp23/cplusplus.C: Adjust expected value.
    	* g++.dg/cpp26/cplusplus.C: New test.
    5388a43f
    History
    c++: Add support for -std={c,gnu}++2{c,6}
    Marek Polacek authored
    It seems prudent to add C++26 now that the first C++26 papers have been
    approved.  I followed commit r11-6920 as well as r8-3237.
    
    Since C++23 is essentially finished and its __cplusplus value has
    settled to 202302L, I've updated cpp_init_builtins and marked
    -std=c++2b Undocumented and made -std=c++23 no longer Undocumented.
    
    As for __cplusplus, I've chosen 202400L:
    
      $ xg++ -std=c++26 -dM -E -x c++ - < /dev/null | grep cplusplus
      #define __cplusplus 202400L
    
    I've verified the patch with a simple test, exercising the new
    directives.  Don't forget to update your GXX_TESTSUITE_STDS!
    
    This patch does not add -Wc++26-extensions.
    
    gcc/c-family/ChangeLog:
    
    	* c-common.h (cxx_dialect): Add cxx26 as a dialect.
    	* c-opts.cc (set_std_cxx26): New.
    	(c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is
    	enabled.
    	(c_common_post_options): Adjust comments.
    	* c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26,
    	and -std=gnu++2c.
    	(std=c++2b): Mark as Undocumented.
    	(std=c++23): No longer Undocumented.
    
    gcc/ChangeLog:
    
    	* doc/cpp.texi (__cplusplus): Document value for -std=c++26 and
    	-std=gnu++26.  Document that for C++23, its value is 202302L.
    	* doc/invoke.texi: Document -std=c++26 and -std=gnu++26.
    	* dwarf2out.cc (highest_c_language): Handle GNU C++26.
    	(gen_compile_unit_die): Likewise.
    
    libcpp/ChangeLog:
    
    	* include/cpplib.h (c_lang): Add CXX26 and GNUCXX26.
    	* init.cc (lang_defaults): Add rows for CXX26 and GNUCXX26.
    	(cpp_init_builtins): Set __cplusplus to 202400L for C++26.
    	Set __cplusplus to 202302L for C++23.
    
    gcc/testsuite/ChangeLog:
    
    	* lib/target-supports.exp (check_effective_target_c++23): Return
    	1 also if check_effective_target_c++26.
    	(check_effective_target_c++23_down): New.
    	(check_effective_target_c++26_only): New.
    	(check_effective_target_c++26): New.
    	* g++.dg/cpp23/cplusplus.C: Adjust expected value.
    	* g++.dg/cpp26/cplusplus.C: New test.