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++.
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++.
Since C++17 you can use the [[nodiscard]] attribute. Example: [[nodiscard]] int bar() { return 42; }
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
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
This is wrong: g++ -c src/CNumber.cpp src/CNumber.h -o src/CNumber.o You shouldn’t “compile” .h files. Doing so will create precompiled header files, which are not used to create an executable. The above should simply be g++ -c src/CNumber.cpp -o src/CNumber.o Similar for compiling the other .cpp files
As the GCC manual says, LIBRARY_PATH is the correct environment variable to add directories to the library search path. If you add -v to the g++ command you should see the LIBRARY_PATH that it uses, and you should see it includes the directory you have specified, and that it gets added to the collect2 command … Read more
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
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’;
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
The surprise This is a subtle Clang bug, deeply buried in the Standard. The problem is that in almost all cases, non-type template arguments can be converted to the type of the template parameter. E.g. the expression Int<0> has an int literal argument of value 0 that is being converted to the type unsigned long … Read more