Reputation: 101
I need to compile my cpp in C++98, not C++11 for my school project.
So I used -std=c++98
to compile:
CPPFLAGS = -Wall -Werror -Wextra -std=c++98
but I made a mistake and use the C++11 std::stoi
function.
i = std::stoi(index);
I tried without the -std=c+=98 flag
but it didn't change anything.
I am working on MAC 10.12.6
My code compiles without any warning or any error.
If I am not mistaken, clang should shout at me for using a C++11 function. Why?
edit clang version:
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
Upvotes: 2
Views: 1667
Reputation: 53
because the -std flag is for 'language standard', 'standard library' is a separate thing. probably the compiler you are using uses libc++ standard library by default. libc++ (llvm std. lib.) still uses c++11 standard library when you get a value lower than c++11 from -std flag. libc++ is owned by llvm. if you want to use gnu standard c++ library (libstdc++) you have to use flag -stdlib=libstdc++. otherwise it uses -stdlib=libc++ by default. Using libstdc++ solved my problem. gnu c++ std. lib. supports 98 standard, llvm c++ std. lib. provides backward compatibility to 98 standard
__cplusplus value getting from -std flag (for 98 -> 199711L)
I see here that libc++ uses the 11 standard for 98
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__config
#ifndef _LIBCPP_STD_VER
# if __cplusplus <= 201103L
# define _LIBCPP_STD_VER 11
# elif __cplusplus <= 201402L
# define _LIBCPP_STD_VER 14
# elif __cplusplus <= 201703L
# define _LIBCPP_STD_VER 17
# else
# define _LIBCPP_STD_VER 18 // current year, or date of c++2a ratification
# endif
#endif // _LIBCPP_STD_VER
Upvotes: 0