The clang compiler emit warnings for the snippet below, as can be seen here.
clang++ -std=c++14 -O0 -Wall -pedantic -pthread main.cpp && ./a.out
main.cpp:1:18: warning: braces around scalar initializer [-Wbraced-scalar-init]
void point(int = {1}, int = {2}) {}
^~~
main.cpp:1:29: warning: braces around scalar initializer [-Wbraced-scalar-init]
void point(int = {1}, int = {2}) {}
^~~
2 warnings generated.
Why is this?
void point(int = {1}, int = {2}) {}
int main(){
point();
}
As far as I can tell, {1}
and {2}
are perfectly valid default arguments according to [dcl.fct.default]/1, [dcl.fct]/3 and [dcl.init]/1.
Notice that clang also defines the GNU C version macros, but you should use the clang feature checking macros to detect the availability of various features. The values of the __clang_major__ , __clang_minor__ , and __clang_patchlevel__ macros are not consistent across distributions of the Clang compiler.
Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.
Clang Design: Like many other compilers design, Clang compiler has three phase: The front end that parses source code, checking it for errors, and builds a language-specific Abstract Syntax Tree (AST) to represent the input code. The optimizer: its goal is to do some optimization on the AST generated by the front end.
The -cc1 argument indicates that the compiler front-end is to be used, and not the driver. The clang -cc1 functionality implements the core compiler functionality. So, simply speaking. If you do not give -cc1 then you can expect the "look&feel" of standard GCC.
Braces are typically used when initializing instances of structs, for example:
struct example {
int member1;
int member2;
};
example x = { 1, 2 };
Clang is telling you that your use of braces isn't "normal" for initializing a single value. This warning could help if you weren't familiar with the syntax for initializing values in C++, or perhaps if the types had previously been structs before a refactoring of some sort.
You can either stop using braces when initializing integers, or pass the -Wno-braced-scalar-init
flag to the compiler to stop it reporting the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With