I’ve Switched On C++20 with Apple Clang

I’ve been watching how C++20 compiler support has evolved over the past 18 months, and as someone using the Apple MacOS platform for my small development projects, I’ve been using the GCC compiler (which I install via Homebrew), along with Visual Studio Code and the Microsoft C/C++ Extension which in my opinion has been the best option so far for my experiments with systems programming.

So, it was great to see that Apple XCode 14 (with Clang 14) set C++20 as it’s default language dialect, whilst not complete in it’s support of C++20, getting to the point at which I had a reasonable choice of compiler and was able to make the switch to the native compiler option on my M1 based Mac was a relief, as my preference has always been to use native tooling as much as possible (I love the simple life 🙂 ).

I realise that most C++ developers will likely fall off their chair in a fit of uncrontrollable laughter at the thought of making Apple Clang the native compiler option for their work – its a personal choice.. I’m not buiding critical apps, mainly playing with the language for small experiments with UI’s API’s etc.

I still use Visual Code Studio (VSC) and found myself wrestling with configurations to get Apple Clang working.. which I did by doing thse two things :

  1. Configure VSC To Use Apple Clang

    When using VSC, a hidden folder named .vscode is created and in this folder, a tasks.json file is created when you try to build / compile code for the first time. The configuration of the json file is not set correctly to enable an error free compilation, so I found that I had to edit this file to add the addtional property of “-std=c++20” as shown in the diagram below in red

  2. Set The Default To C++20

    When building code, many of the C++20 additions such as costeval show up in VSC with a squiggly red line under them, which is showing something that’s incorrect or could cause an issue. To fix this, a modification to the User Settings UI is required … Via the View menu, selecting the Command Palette and searching for the “C/C++ Edit Configurations (UI)” which brings up the C/C++ Extension Configurations… scrolling down to the bottom of the options allows the standard release of C++ to be set to 20, as shown in the diagram below:

I’m now happily using this combination of Apple Clang 14 with VSC and looking forward to seeing the continued support for C++20 and 23 continuing 🙂

Comments are closed.

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: