@@ -3786,56 +3786,105 @@ void simplecpp::cleanup(std::map<std::string, TokenList*> &filedata)
37863786 filedata.clear ();
37873787}
37883788
3789- std::string simplecpp::getCStdString (const std::string &std)
3789+ simplecpp:: cstd_t simplecpp::getCStd (const std::string &std)
37903790{
3791- if (std == " c90" || std == " c89" || std == " iso9899:1990" || std == " iso9899:199409" || std == " gnu90" || std == " gnu89" ) {
3792- // __STDC_VERSION__ is not set for C90 although the macro was added in the 1994 amendments
3793- return " " ;
3794- }
3791+ if (std == " c90" || std == " c89" || std == " iso9899:1990" || std == " iso9899:199409" || std == " gnu90" || std == " gnu89" )
3792+ return C89;
37953793 if (std == " c99" || std == " c9x" || std == " iso9899:1999" || std == " iso9899:199x" || std == " gnu99" || std == " gnu9x" )
3796- return " 199901L " ;
3794+ return C99 ;
37973795 if (std == " c11" || std == " c1x" || std == " iso9899:2011" || std == " gnu11" || std == " gnu1x" )
3798- return " 201112L " ;
3796+ return C11 ;
37993797 if (std == " c17" || std == " c18" || std == " iso9899:2017" || std == " iso9899:2018" || std == " gnu17" || std == " gnu18" )
3800- return " 201710L" ;
3801- if (std == " c23" || std == " gnu23" || std == " c2x" || std == " gnu2x" ) {
3802- // supported by GCC 9+ and Clang 9+
3803- // Clang 9, 10, 11, 12, 13 return "201710L"
3804- // Clang 14, 15, 16, 17 return "202000L"
3805- // Clang 9, 10, 11, 12, 13, 14, 15, 16, 17 do not support "c23" and "gnu23"
3806- return " 202311L" ;
3798+ return C17;
3799+ if (std == " c23" || std == " gnu23" || std == " c2x" || std == " gnu2x" )
3800+ return C23;
3801+ return CUnknown;
3802+ }
3803+
3804+ std::string simplecpp::getCStdString (cstd_t std)
3805+ {
3806+ switch (std)
3807+ {
3808+ case C89:
3809+ // __STDC_VERSION__ is not set for C90 although the macro was added in the 1994 amendments
3810+ return " " ;
3811+ case C99:
3812+ return " 199901L" ;
3813+ case C11:
3814+ return " 201112L" ;
3815+ case C17:
3816+ return " 201710L" ;
3817+ case C23:
3818+ // supported by GCC 9+ and Clang 9+
3819+ // Clang 9, 10, 11, 12, 13 return "201710L"
3820+ // Clang 14, 15, 16, 17 return "202000L"
3821+ // Clang 9, 10, 11, 12, 13, 14, 15, 16, 17 do not support "c23" and "gnu23"
3822+ return " 202311L" ;
3823+ case CUnknown:
3824+ return " " ;
38073825 }
38083826 return " " ;
38093827}
38103828
3811- std::string simplecpp::getCppStdString (const std::string &std)
3829+ std::string simplecpp::getCStdString (const std::string &std)
3830+ {
3831+ return getCStdString (getCStd (std));
3832+ }
3833+
3834+ simplecpp::cppstd_t simplecpp::getCppStd (const std::string &std)
38123835{
38133836 if (std == " c++98" || std == " c++03" || std == " gnu++98" || std == " gnu++03" )
3814- return " 199711L " ;
3837+ return CPP03 ;
38153838 if (std == " c++11" || std == " gnu++11" || std == " c++0x" || std == " gnu++0x" )
3816- return " 201103L " ;
3839+ return CPP11 ;
38173840 if (std == " c++14" || std == " c++1y" || std == " gnu++14" || std == " gnu++1y" )
3818- return " 201402L " ;
3841+ return CPP14 ;
38193842 if (std == " c++17" || std == " c++1z" || std == " gnu++17" || std == " gnu++1z" )
3820- return " 201703L" ;
3821- if (std == " c++20" || std == " c++2a" || std == " gnu++20" || std == " gnu++2a" ) {
3822- // GCC 10 returns "201703L" - correct in 11+
3823- return " 202002L" ;
3824- }
3825- if (std == " c++23" || std == " c++2b" || std == " gnu++23" || std == " gnu++2b" ) {
3826- // supported by GCC 11+ and Clang 12+
3827- // GCC 11, 12, 13 return "202100L"
3828- // Clang 12, 13, 14, 15, 16 do not support "c++23" and "gnu++23" and return "202101L"
3829- // Clang 17, 18 return "202302L"
3830- return " 202302L" ;
3831- }
3832- if (std == " c++26" || std == " c++2c" || std == " gnu++26" || std == " gnu++2c" ) {
3833- // supported by Clang 17+
3834- return " 202400L" ;
3843+ return CPP17;
3844+ if (std == " c++20" || std == " c++2a" || std == " gnu++20" || std == " gnu++2a" )
3845+ return CPP20;
3846+ if (std == " c++23" || std == " c++2b" || std == " gnu++23" || std == " gnu++2b" )
3847+ return CPP23;
3848+ if (std == " c++26" || std == " c++2c" || std == " gnu++26" || std == " gnu++2c" )
3849+ return CPP26;
3850+ return CPPUnknown;
3851+ }
3852+
3853+ std::string simplecpp::getCppStdString (cppstd_t std)
3854+ {
3855+ switch (std)
3856+ {
3857+ case CPP03:
3858+ return " 199711L" ;
3859+ case CPP11:
3860+ return " 201103L" ;
3861+ case CPP14:
3862+ return " 201402L" ;
3863+ case CPP17:
3864+ return " 201703L" ;
3865+ case CPP20:
3866+ // GCC 10 returns "201703L" - correct in 11+
3867+ return " 202002L" ;
3868+ case CPP23:
3869+ // supported by GCC 11+ and Clang 12+
3870+ // GCC 11, 12, 13 return "202100L"
3871+ // Clang 12, 13, 14, 15, 16 do not support "c++23" and "gnu++23" and return "202101L"
3872+ // Clang 17, 18 return "202302L"
3873+ return " 202302L" ;
3874+ case CPP26:
3875+ // supported by Clang 17+
3876+ return " 202400L" ;
3877+ case CPPUnknown:
3878+ return " " ;
38353879 }
38363880 return " " ;
38373881}
38383882
3883+ std::string simplecpp::getCppStdString (const std::string &std)
3884+ {
3885+ return getCppStdString (getCppStd (std));
3886+ }
3887+
38393888#if (__cplusplus < 201103L) && !defined(__APPLE__)
38403889#undef nullptr
38413890#endif
0 commit comments