User forums > Help

Why don't any recent C++ versions appear in the compiler settings?

(1/3) > >>

logicalwillow:
KDE neon 5.23, Code::Blocks 20.03 rev 11997, gcc 11.2.0. I installed Code::Blocks from Flathub
So, I'm trying to learn C++. The tutorial I'm using to learn it recommends using C++17 or C++20 to get the best experience on the site. The problem is that the two (yes, just two) C++ options I found in the compiler settings were for 1998.

I tried on a Windows 11 machine, and every option showed up as expected, such as "Have g++ follow the C++17 ISO C++ language standard [-std=c++17]" along with some slightly older versions (14, 11, etc.) which is what I was expecting to see on my Linux machine. But I don't see it.

The tutorial has some example code that you can compile to test C++17 compatibility:

--- Code: ---#include <array>
#include <iostream>
#include <string_view>
#include <tuple>
#include <type_traits>

namespace a::b::c
{
    inline constexpr std::string_view str{ "hello" };
}

template <class... T>
std::tuple<std::size_t, std::common_type_t<T...>> sum(T... args)
{
    return { sizeof...(T), (args + ...) };
}

int main()
{
    auto [iNumbers, iSum]{ sum(1, 2, 3) };
    std::cout << a::b::c::str << ' ' << iNumbers << ' ' << iSum << '\n';

    std::array arr{ 1, 2, 3 };

    std::cout << std::size(arr) << '\n';

    return 0;
}
--- End code ---

I compiled this code and I got no errors. I also compiled some other code to see what C++ version I had, and it said C++17. This was the code:

--- Code: ---#include <iostream>

int main() {
    if (__cplusplus == 201703L) std::cout << "C++17\n";
    else if (__cplusplus == 201402L) std::cout << "C++14\n";
    else if (__cplusplus == 201103L) std::cout << "C++11\n";
    else if (__cplusplus == 199711L) std::cout << "C++98\n";
    else std::cout << "pre-standard C++\n";
}
--- End code ---

If I can use C++17, why don't any new C++ versions show up in the compiler settings, and how do I fix it?

Also, please let me know if I should move this post to another category. I think this is a compiler issue, so maybe it should be put somewhere else.

If you're wondering why I installed Code::Blocks from Flathub instead of from my system's package manager or the website, it's because Code::Blocks doesn't look very good with a dark theme, and for some reason Flatpaks just don't want to respect the system theme, so this works for Code::Blocks, I guess.

AndrewCot:
C::B 20.03 has the option for GCC "-std=c17".

If you want C++20 standard you have two options:
1) Download and use the nightly build as it includes the options included in 2) below.
2) Add either of the following in the "Other compiler options tab":
    -std=c++20
    -std=gnu++20
    -std=c++2a
    -std=gnu++2a

But before using these make sure you read the GNU GCC Standards support for the version of GCC you are using as they may not support all of the C++20 or even the C++17 standards depending on the version you are have.

If you want to use eh GNU C++23 standard then lookup the GNU GCC Stanards support for what the compiler option is and how compatible the version you have is.

Miguel Gimenez:
Can anybody with gcc11 check if this command works on command line?

--- Code: ---gcc -dumpversion
--- End code ---

We rely on this command to show flags, and I know gcc devs wanted to remove it some time ago.

stahta01:

--- Code: ---$ gcc -dumpversion
11.2.0

--- End code ---

MSys2 64 bit mingw


--- Code: ---$ gcc --version
gcc.exe (Rev5, Built by MSYS2 project) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
--- End code ---

Tim S.

stahta01:

--- Quote ---Code::Blocks from Flathub
--- End quote ---

6 months ago this was known to not work!

Edit: Add link https://forums.codeblocks.org/index.php/topic,23943.msg163332.html#msg163332

Tim S.

Navigation

[0] Message Index

[#] Next page

Go to full version