Scope resolution operator

This code is not valid. It was a bug in g++ that it accepted the code. See “g++ does not treat injected class name correctly.” The bug was resolved as fixed in 2009, so it should be fixed in any recent version of g++.

Selecting message language in gcc and g++

The end of the GCC manpage contains an overview of its locale environment variables: LANG LC_CTYPE LC_MESSAGES LC_ALL These environment variables control the way that GCC uses localization information that allow GCC to work with different national conventions. GCC inspects the locale categories LC_CTYPE and LC_MESSAGES if it has been configured to do so. These … Read more

How to compile openmp using g++

OpenMP is a set of code transforming pragmas, i.e. they are only applied at compile time. You cannot apply code transformation to an already compiled object code (ok, you can, but it is far more involving process and outside the scope of what most compilers do these days). You need -fopenmp during the link phase … Read more

How to explicitly call a namespace-qualified destructor?

In the standard, at: ยง3.4.5/3 If the unqualified-id is ~type-name, the type-name is looked up in the context of the entire postfix-expression. therefore it would seem that ~string should be looked up in the context of the std:: namespace. In fact, considering that a corresponding home-made version works as follows on both GCC and Clang: … Read more

How to copy a string into a char array in C++ without going over the buffer

This is exactly what std::string‘s copy function does. #include <string> #include <iostream> int main() { char test[5]; std::string str( “Hello, world” ); str.copy(test, 5); std::cout.write(test, 5); std::cout.put(‘\n’); return 0; } If you need null termination you should do something like this: str.copy(test, 4); test[4] = ‘\0’;

Handling gcc’s noexcept-type warning

There’s several things you can do about the warning message. Disable it with -Wno-noexcept-type. In many projects the warning message is unhelpful because there’s no chance the resulting object will be linked with an another object that expects it to use GCC’s C++17 name mangling. If you’re not compiling with different -std= settings and you’re … Read more