简体   繁体   中英

XCode project's choice of C++ standard is not being respected

I'm playing around with XCode and C++, and I noticed that I change the C++ standard (ie C++98, C++11, GNU17, etc.) by clicking my project in the left sidebar. See screenshot at bottom of this post.

However, when I change to C++98, the C++ statement auto x = 6; still compiles and runs with no complaints. This is bad because auto requires C++11, so clearly my setting of the standard to C++98 is not in effect. Note that when I say "still compile and run", I mean that I'm clicking the "play" button in XCode.

I imagine several possibilities here:

  • there's some super hidden "save" button that I missed that I'm required to click to actually get the setting to stick
  • the action of "clicking the play button in XCode" does not actually use the new setting but rather uses old settings (and there needs be some kind of "make clean"-like ritual I need to do first in order to get the "play" button to respect new project settings
  • this setting is not working at all and it's a bug in XCode

Anyone know what I'm doing wrong here? I'm using XCode 13.4.1 (latest version as of July 2022) on macOS monterey on 2021 macbook pro 14 inch with M1 pro.

在此处输入图像描述

There's another possibility you overlooked:

auto x = 6;

This happens to be a perfectly valid declaration in prehistoric times. auto meant something else entirely, and traces its lineage to C. Nobody was using it, so the keyword was re-purposed in C++11. But, this just happens to be valid code. You might want to try something like:

auto y = "hello world";

and then verify the behavior of your C++ compiler at various C++ levels.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM