{"id":2084,"date":"2015-01-06T08:43:10","date_gmt":"2015-01-06T07:43:10","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?page_id=2084"},"modified":"2026-04-23T10:27:21","modified_gmt":"2026-04-23T09:27:21","slug":"gnu-compiler-collection","status":"publish","type":"page","link":"http:\/\/roboblog.fatal-fury.de\/?page_id=2084","title":{"rendered":"GNU compiler collection - Useful GCC warning\/errors not enabled by Wall Wextra"},"content":{"rendered":"<p>Check cache size cat \/sys\/devices\/system\/cpu\/cpu0\/cache\/index3\/size or lstopo<\/p>\n<p><a href=\"https:\/\/gcc.gnu.org\/onlinedocs\/gcc\/\">https:\/\/gcc.gnu.org\/onlinedocs\/gcc\/<\/a><br \/>\n<a href=\"https:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/manual\/debug_mode.html\">https:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/manual\/debug_mode.html<\/a><\/p>\n<p>TODO  -Werror=attributes<\/p>\n<p><a href=\"#padded\">-Werror=padded<\/a><br \/>\n<a href=\"#shadow\">-Werror=shadow<\/a><br \/>\n<a href=\"#pedantic\">-Werror=pedantic<\/a><br \/>\n<a href=\"#nulldereference\">-Werror=null-dereference<\/a><br \/>\n<a href=\"#exceptions\">-Werror=exceptions<\/a><br \/>\n<a href=\"#catch-value\">-Werror=catch-value<\/a><\/p>\n<p>Hier die Zusammenfassung C&P in eure Projekt Datei. Mit GCC Version Test<br \/>\n<code><br \/>\n{<br \/>\n    GCC_VERSION = &#x24;&#x24;system(&#x24;&#x24;QMAKE_CXX \" -dumpversion\")<br \/>\n    VERSIONS = &#x24;&#x24;split(GCC_VERSION, .)<br \/>\n    VERSION_MAJ = &#x24;&#x24;member(VERSIONS)<\/p>\n<p>    contains(VERSION_MAJ, 12) {<br \/>\n        message( \"g++ version 12.x found\" )<br \/>\n        CONFIG += g++12<br \/>\n    }<br \/>\n    contains(VERSION_MAJ, 11) {<br \/>\n        message( \"g++ version 11.x found\" )<br \/>\n        CONFIG += g++11<br \/>\n    }<br \/>\n    contains(VERSION_MAJ, 10) {<br \/>\n        message( \"g++ version 10.x found\" )<br \/>\n        CONFIG += g++10<br \/>\n    }<br \/>\n    contains(VERSION_MAJ, 9) {<br \/>\n        message( \"g++ version 9.x found\" )<br \/>\n        CONFIG += g++9<br \/>\n    }<br \/>\n    contains(VERSION_MAJ, 8) {<br \/>\n        message( \"g++ version 8.x found\" )<br \/>\n        CONFIG += g++8<br \/>\n    }<br \/>\n    contains(VERSION_MAJ, 7) {<br \/>\n        message( \"g++ version 7.x found\" )<br \/>\n        CONFIG += g++7<br \/>\n    }<br \/>\n    contains(VERSION_MAJ, 6) {<br \/>\n        message( \"g++ version 6.x found\" )<br \/>\n        CONFIG += g++6<br \/>\n    }<br \/>\n    contains(VERSION_MAJ, 5) {<br \/>\n        message( \"g++ version 5.x found\" )<br \/>\n        CONFIG += g++5<br \/>\n    }<br \/>\n    contains(VERSION_MAJ, 4) {<br \/>\n        message( \"g++ version 4.x found\" )<br \/>\n        CONFIG += g++4<br \/>\n    }<br \/>\n}<\/p>\n<p>g++8|g++9|g++10|g++11|g++12: QMAKE_CXXFLAGS += -Werror=class-memaccess<br \/>\ng++9|g++10|g++11|g++12: QMAKE_CXXFLAGS += -Werror=init-list-lifetime -Werror=redundant-move -Werror=pessimizing-move -Werror=class-conversion<br \/>\ng++10|g++11|g++12: QMAKE_CXXFLAGS += -Werror=comma-subscript<br \/>\ng++11|g++12: QMAKE_CXXFLAGS += -Werror=range-loop-construct  -Werror=deprecated-enum-enum-conversion -Werror=deprecated-enum-float-conversion -Werror=mismatched-new-delete -Werror=vexing-parse<br \/>\ng++12: QMAKE_CXXFLAGS += -Werror=missing-requires -Werror=int-in-bool-context -Werror=bidi-chars=any -Werror=array-compare<\/p>\n<p>QMAKE_CXXFLAGS_DEBUG +=  -D_GLIBCXX_DEBUG<br \/>\nQMAKE_CXXFLAGS += -Wpedantic -Werror=extra -Wno-error=sign-compare -Wno-error=unused-parameter<br \/>\nQMAKE_CXXFLAGS += -Wvector-operation-performance -Werror=div-by-zero  -Werror=multichar -Werror=switch -Werror=switch-enum -Werror=switch-bool -Werror=switch-unreachable<br \/>\nQMAKE_CXXFLAGS += -Werror=pedantic  -pedantic-errors -Werror=unused-value -Werror=overflow -Werror=address -Werror=tautological-compare<br \/>\nQMAKE_CXXFLAGS += -Werror=narrowing -Werror=return-type -Werror=misleading-indentation -Werror=strict-aliasing -Werror=sign-promo<br \/>\nQMAKE_CXXFLAGS += -Werror=parentheses -Werror=logical-not-parentheses -Werror=logical-op -Werror=bool-compare -Werror=uninitialized -Werror=maybe-uninitialized<br \/>\nQMAKE_CXXFLAGS += -Werror=unused-result -Werror=reorder -Werror=duplicated-cond -Werror=duplicated-branches -Werror=type-limits -Werror=missing-field-initializers<br \/>\nQMAKE_CXXFLAGS += -Werror=return-local-addr -Werror=sequence-point -Werror=dangling-else -Werror=conversion-null -Werror=empty-body  -Werror=ignored-qualifiers -Werror=null-dereference<br \/>\n# lot of work<br \/>\n# QMAKE_CXXFLAGS += -Werror=conversion<br \/>\n# we love pain<br \/>\n# QMAKE_CXXFLAGS += -Werror=shadow<\/p>\n<p># The QT library is not free of warnings. If we enable e.g. -Wconversion we see a lot<br \/>\n# of warnings from Qt we cant fix nor care. Here is a simple way to disable warnings<br \/>\n# for external framwork. Just  include library headers using -isystem instead of -I.<br \/>\n# This will make them \"system headers\" and GCC won't report warnings for them.<br \/>\n# This still trigger some warnings due to inline of code.<br \/>\n# If a standard system include directory, or a directory specified with -isystem, is also specified with -I, the -I option is ignored.<br \/>\nQMAKE_CXXFLAGS += -isystem<span class='MathJax_Preview'><img src='http:\/\/roboblog.fatal-fury.de\/wp-content\/plugins\/latex\/cache\/tex_4adf30059a9a8b68901c1e2d99072ae3.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>[QT_INSTALL_HEADERS]\/QtWidgets<br \/>\nQMAKE_CXXFLAGS += -isystem<span class='MathJax_Preview'><img src='http:\/\/roboblog.fatal-fury.de\/wp-content\/plugins\/latex\/cache\/tex_48f10c601b4057bcb712b8e9ee209452.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>[QT_INSTALL_HEADERS]\/QtNetwork<br \/>\nQMAKE_CXXFLAGS += -isystem<span class='MathJax_Preview'><img src='http:\/\/roboblog.fatal-fury.de\/wp-content\/plugins\/latex\/cache\/tex_4f9078ff305bdea94f9578751b872aca.gif' style='vertical-align: middle; border: none; ' class='tex' alt=\"\" \/><\/span><script type='math\/tex'><\/script>[QT_INSTALL_HEADERS]\/QtScript<br \/>\nQMAKE_CXXFLAGS += -isystem$$[QT_INSTALL_HEADERS]\/QtTest<\/p>\n<p><\/code><\/p>\n<h1>Unabdingbar!!!<\/h1>\n<p>TODO  -Werror=range-loop-construct  -Werror=deprecated-enum-enum-conversion -Werror=deprecated-enum-float-conversion -Werror=mismatched-new-delete -Werror=vexing-parse<br \/>\nTODO GCC12 -Wno-missing-requires   -Wint-in-bool-context -Wbidi-chars=[none|unpaired|any|ucn] -Warray-compare<\/p>\n<h2><strong>-Werror=extra<\/strong><\/h2>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct A { };\r\n\r\nstruct B {\r\n    B(A) {};\r\n};\r\n\r\nstruct C {\r\n    C(const A&amp; a)\r\n    : b(B(a)) \/\/ error: a temporary bound to &#039;C::b&#039; only persists until the constructor exits\r\n    {\r\n    }\r\n\r\n    const B&amp; b; \/\/ Do not store references\r\n};\r\n}\r\n<\/pre>\n<h2><strong>-Werror=return-type<\/strong><\/h2>\n<p>Eine vergessene return Anweisung f\u00fcr zu 99% zum segfault.  <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nint func() {   \r\n\/\/ error: no return statement in function returning non-void\r\n}\r\n<\/pre>\n<p><strong>-Werror=return-local-addr<\/strong><br \/>\nLokale Konstanten als const referenzen zur\u00fcckgeben f\u00fchrt leider zum sefault;<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nconst int&amp; func() {\r\n    return 0; \/\/ error: returning reference to temporary\r\n}\r\n<\/pre>\n<p><strong>-Werror=uninitialized<\/strong><br \/>\nError if an automatic variable is used without first being initialized.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nauto func()  {\r\n    double X;\r\n    return X; \/\/ error: &#039;X&#039; is used uninitialized in this function\r\n}\r\n<\/pre>\n<p><strong>-Werror=unused-value<\/strong><br \/>\nWarn whenever a statement computes a result that is explicitly not used. This includes an expression-statement or the left-hand side of a comma expression that contains no side effects.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nauto func(std::vector&lt;int&gt; v, int i, int j) {  \r\n  return v&#x5B;i,j];                               \/\/  error: left operand of comma operator has no effect\r\n} \r\n<\/pre>\n<p><strong>  -Werror=comma-subscript<\/strong><br \/>\nWarn about uses of a comma expression within a subscripting expression. This usage was deprecated in C++20. However<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nauto func(std::vector&lt;int&gt; v, int i, int j) {  \r\n  return v&#x5B;i,j];                               \/\/  error: top-level comma expression in array subscript is deprecated\r\n} \r\n<\/pre>\n<p><strong>-Werror=missing-field-initializers<\/strong><br \/>\nWarn if a structure\u2019s initializer has some fields missing.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct X {    \r\n  int a,b,c; \r\n};\r\nX x{1, 2};    \/\/ error: missing initializer for member &#039;X::c&#039;\r\n<\/pre>\n<p><strong>-Werror=maybe-uninitialized<\/strong><br \/>\nFor an automatic (i.e. local) variable, if there exists a path from the function entry to a use of the variable that is initialized, but there exist some other paths for which the variable is not initialized, the compiler emits a warning if it cannot prove the uninitialized paths are not executed at run time. <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n    double T=0, dt;\r\n    for (double t=0; t&lt;T; t+=dt) { } \/\/ error: &#039;dt&#039; may be used uninitialized in this function\r\n<\/pre>\n<p><strong>-Werror=unused-result<\/strong><br \/>\nError if a caller of a function does not use its return value \/ if the return value is discarded.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n&#x5B;&#x5B;nodiscard]] int bar(int);\r\nauto foo() {\r\n    bar(3); \/\/ error: ignoring return value of &#039;int bar(int)&#039;, declared with attribute nodiscard\r\n}\r\n<\/pre>\n<p><strong>-Werror=narrowing<\/strong><br \/>\nWhen you try something not possible.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nint func(double a) {\r\n    return {a};    \/\/  error: narrowing conversion of &#039;a&#039; from &#039;double&#039; to &#039;int&#039; inside { } \r\n}\r\n<\/pre>\n<p><strong>-Werror=address<\/strong><br \/>\nError about suspicious uses of memory addresses, e.g. comparisons against the memory address of a string literal.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nif(g-&gt;name == &quot;quad&quot;)   \/\/ error: comparison with string literal results in unspecified behavior\r\n<\/pre>\n<p><strong>-Werror=misleading-indentation<\/strong><br \/>\nError when the indentation of the code does not reflect the block structure.  <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid a();\r\nvoid b();\r\nvoid func() {   \r\n    for(int i=0; i &lt; 10; ++i) \/\/  error: this &#039;for&#039; clause does not guard...\r\n      a();\r\n      b();                    \/\/ ...this statement, but the latter is misleadingly indented as if it were guarded by the &#039;for&#039;\r\n}\r\n<\/pre>\n<p><strong>-Werror=strict-aliasing<\/strong><br \/>\nError about code that might break the strict aliasing rules that the compiler is using for optimization.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nint i=0;\r\nfloat f = *reinterpret_cast&lt;float*&gt;(&amp;i); \/\/ error: dereferencing type-punned pointer will break strict-aliasing rule\r\ni = *(int*)&amp;f;                               \/\/ error: dereferencing type-punned pointer will break strict-aliasing rule\r\n<\/pre>\n<p><strong>-Werror=sign-promo<\/strong><br \/>\nError when overload resolution chooses a promotion from unsigned or enumerated type to a signed type, over a conversion to an unsigned type of the same size.<br \/>\nA function with a signed parameter is called with a unsigned argument, instead of the function with an unsigned parameter.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nvoid func(int32_t);\r\nvoid func(uint32_t);\r\nfunc(uint8_t()); \/\/ error: passing &#039;uint8_t&#039; {aka &#039;unsigned char&#039;} chooses &#039;int32_t&#039; {aka &#039;int&#039;} over &#039;uint32_t&#039; {aka &#039;unsigned int&#039;}\r\nfunc(int8_t()); \/\/ ok\r\nfunc(uint16_t()); \/\/ error: passing &#039;uint16_t&#039; {aka &#039;short unsigned int&#039;} chooses &#039;int32_t&#039; {aka &#039;int&#039;} over &#039;uint32_t&#039; {aka &#039;unsigned int&#039;}\r\nenum noClassEnum { A };\r\nfunc(e); \/\/ error: passing &#039;noClassEnum&#039; chooses &#039;int32_t&#039; {aka &#039;int&#039;} over &#039;uint32_t&#039; {aka &#039;unsigned int&#039;}\r\n<\/pre>\n<p><strong> -Werror=dangling-else<\/strong><br \/>\nError about constructions where there may be confusion to which if statement an else branch belongs. <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nif(true)       \/\/ error: suggest explicit braces to avoid ambiguous &#039;else&#039;\r\n  if(false)\r\n    return 0;\r\n  else\r\n    return 1;  \r\n<\/pre>\n<p><strong>-Werror=parentheses<\/strong><br \/>\nError if parentheses are omitted in certain contexts, such as when there is an assignment in a context where a truth value is expected, or when operators are nested whose precedence people often get confused about.               ^<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nint (a);          \/\/ error: unnecessary parentheses in declaration of &#039;a&#039;\r\nif(a = 1)         \/\/ error: suggest parentheses around assignment used as truth value\r\n<\/pre>\n<p><strong>-Werror=logical-not-parentheses<\/strong><br \/>\nError about logical not used on the left hand side operand of a comparison.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nif(!a == 1)   \/\/ error: logical not is only applied to the left hand side of comparison\r\n              \/\/ note: add parentheses around left hand side expression\r\n<\/pre>\n<p><strong>-Werror=logical-op<\/strong><br \/>\nError about suspicious uses of logical operators in expressions. This includes using logical operators in contexts where a bit-wise operator is likely to be expected. Also warns when the operands of a logical operator are the same: <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n    if((a &amp;&amp; 0b10) or (a &amp;&amp; 0b10)) {} \/\/ error: logical &#039;and&#039; applied to non-boolean constant\r\n                                      \/\/ error: logical &#039;or&#039; of equal expressions\r\n<\/pre>\n<p><strong>-Werror=bool-compare<\/strong><br \/>\nError about boolean expression compared with an integer value different from true\/false<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n return (x &gt; 0) == 2;    \/\/   error: comparison of constant &#039;2&#039; with boolean expression is always false\r\n<\/pre>\n<p><strong>-Werror=switch<\/strong><br \/>\nError whenever a switch statement has an index of enumerated type and lacks a case for one or more of the named codes of that enumeration. (The presence of a default label prevents this warning.)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nerror: enumeration value &#039;unknown&#039; not handled in switch\r\n<\/pre>\n<p>See next.<\/p>\n<p><strong>-Werror=switch-enum<\/strong><br \/>\nThe only difference between -Wswitch and this option is that this option gives a warning about an omitted enumeration code even if there is a default label. <\/p>\n<p><strong>-Werror=switch-bool<\/strong><br \/>\nWarn whenever a switch statement has an index of boolean type and the case values are outside the range of a boolean type<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nauto func(int type) {\r\n    switch (type==4) {  \/\/ error: switch condition has boolean value\r\n        case 2:;\r\n    }\r\n}\r\n<\/pre>\n<p><strong>-Werror=switch-unreachable<\/strong><br \/>\nWarn whenever a switch statement contains statements between the controlling expression and the first case label, which will never be executed.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nauto func(int type) {\r\n    switch (type) {\r\n        int i = 0;   \/\/ note:   crosses initialization of &#039;int i&#039;\r\n        case 2:;     \/\/ error: jump to case label\r\n                     \/\/ error: statement will never be executed\r\n    }\r\n}\r\n<\/pre>\n<p><strong>-Werror=implicit-fallthrough=3<\/strong><br \/>\nError when a switch case falls through.<br \/>\nC++17 provides a standard way to suppress error using [[fallthrough]]; attribute.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nerror: this statement may fall through\r\n<\/pre>\n<p><strong>-Werror=reorder<\/strong><br \/>\nWarn when the order of member initializers given in the code does not match the order in which they must be executed.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct A {\r\n  int i;\r\n  int j;                 \/\/ error: &#039;A::j&#039; will be initialized after &#039;int A::i&#039;\r\n  A(): j (0), i (1) { }  \/\/ error: when initialized here\r\n};\r\n<\/pre>\n<p><strong>-Werror=duplicated-cond<\/strong><br \/>\nWarn about duplicated conditions in an if-else-if chain. <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n    if(a == 0) {          \/\/ note: previously used here\r\n    } else if (a == 0) {  \/\/ error: duplicated &#039;if&#039; condition\r\n    }\r\n<\/pre>\n<p><strong>-Werror=duplicated-branches<\/strong><br \/>\nWarn about duplicated conditions in an if-else-if chain.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n    if(a == 0) {     \/\/ error: this condition has identical branches\r\n        return 1;\r\n    } else  {\r\n        return 1;\r\n    }\r\n<\/pre>\n<p><strong>-Werror=type-limits<\/strong><br \/>\nError if a comparison is always true or always false due to the limited range of the data type.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nauto func(unsigned int x) {\r\n  return x &gt;= 0;    \/\/ error: comparison of unsigned expression &gt;= 0 is always true\r\n}\r\n<\/pre>\n<p><strong>-Werror=tautological-compare<\/strong><br \/>\nError if a self-comparison always evaluates to true or false, or about bitwise comparisons that always evaluate to true or false.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nauto func(int i) {\r\n  return i &gt;= i;  \/\/  error: self-comparison always evaluates to true\r\n}\r\n<\/pre>\n<p><strong>-Werror=empty-body<\/strong><br \/>\nPassiert...<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nif(1==2);  \/\/ error: suggest braces around empty body in an &#039;if&#039; statement\r\n<\/pre>\n<p><strong>-Werror=ignored-qualifiers<\/strong><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nconst int func() {  \/\/ error: type qualifiers ignored on function return type\r\n    return 42;\r\n}\r\n<\/pre>\n<p><strong>-Werror=sequence-point<\/strong><br \/>\nError about code that may have undefined semantics because of violations of sequence point rules in the C and C++ standards. There is more to read in the GCC manual.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nauto func(int i) {\r\n  return i++ + ++i;  \/\/  error: operation on &#039;i&#039; may be undefined \r\n}\r\n<\/pre>\n<p><strong>-Werror=div-by-zero<\/strong><br \/>\nError on compile-time integer division by zero. Floating-point division by zero is not warned about.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n  while(pos_nextRecord \/= 0) { \/\/ error: division by zero &#x5B;-Werror=div-by-zero]\r\n<\/pre>\n<p><strong>-Werror=multichar<\/strong><br \/>\nError if a multicharacter constant (\u2018'FOOF'\u2019) is used.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n  std::cout &lt;&lt; &#039; kB\\n&#039;;  \/\/ error: multi-character character constant\r\n<\/pre>\n<p><strong>-Werror=class-conversion<\/strong><br \/>\nError about the case when a conversion function will never be called. <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct U {};\r\n\r\nstruct T : U { \r\n  operator T() { \/\/ error: converting &#039;T&#039; to the same type will never use a type conversion operator\r\n  }\r\n\r\n  operator U() { \/\/ errro  converting &#039;T&#039; to a base class &#039;U&#039; will never use a type conversion operator\r\n  }\r\n  \r\n  operator void() { \/\/ error: converting &#039;T&#039; to &#039;void&#039; will never use a type conversion operator\r\n  }\r\n};\r\n<\/pre>\n<p><strong>-Werror=conversion-null<\/strong><br \/>\nOffensichtlich <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nint func() {\r\n    return NULL; \/\/ error converting to non-pointer type &#039;int&#039; from NULL\r\n}\r\n<\/pre>\n<p><strong>-Werror=redundant-move<\/strong><br \/>\nError about redundant calls to std::move.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nT fn(T t) {\r\n  return std::move(t); \/\/ error: redundant move in return statement\r\n}\r\n<\/pre>\n<p><strong>-Werror=pessimizing-move<\/strong><br \/>\nError when a call to std::move prevents copy elision. <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nT fn() {\r\n  T t;\r\n  return std::move(t); \/\/ error: moving a local object in a return statement prevents copy elision\r\n}\r\n<\/pre>\n<p><strong>-Werror=init-list-lifetime<\/strong><br \/>\nError about uses of std::initializer_list that are likely to result in dangling pointers. <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n\/\/ initializer_list underlying array\u2019s lifetime ends at the end of the return statement\r\nauto func1() {\r\n  std::initializer_list&lt;int&gt; li = { 1,2,3 }; \r\n  return li;  \/\/ error: returning local initializer_list variable &#039;li&#039; does not extend the lifetime of the underlying array\r\n}\r\n\r\n\/\/ li&#039;s initial underlying array lives as long as li\r\n\/\/ assignment changes li to point to a temporary array\r\nauto func2() {\r\n  std::initializer_list&lt;int&gt; li = { 1,2,3 };\r\n  li = { 4, 5 }; \/\/ error: assignment from temporary initializer_list does not extend the lifetime of the underlying array\r\n}\r\n\r\n\/\/ When a list constructor stores the begin pointer from the initializer_list argument, this doesn\u2019t extend the lifetime of the array. \r\n\/\/ so if a class variable is constructed from a temporary initializer_list,\r\n\/\/ the pointer is left dangling by the end of the variable declaration statement. \r\nstruct A {\r\n  A(std::initializer_list&lt;int&gt; li) \r\n  : p(li.begin()) \/\/ error: initializing &#039;A::p&#039; from &#039;std::initializer_list&lt;int&gt;::begin&#039; does not extend the lifetime of the underlying array\r\n  {\r\n  }\r\n\r\n  const int* p;\r\n};\r\n<\/pre>\n<p><strong>-Werror=class-memaccess <\/strong><br \/>\nWarn when the destination of a call to a raw memory function such as memset or memcpy is an object of class type, and when writing into such an object might bypass the class non-trivial or deleted constructor or copy assignment, violate const-correctness or encapsulation, or corrupt virtual table pointers.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct A {\r\n    A() = default;\r\n    A(A&amp;) { };\r\n};\r\n\r\nstatic_assert( std::is_trivially_copyable&lt;A&gt;::value);  \/\/ error: static assertion failed\r\n\r\nauto func() {\r\n    A a, b;\r\n    memcpy(&amp;b, &amp;a, sizeof(b)); \/\/ error: &#039;void* memcpy(void*, const void*, size_t)&#039; writing to an object of non-trivially copyable type &#039;struct A&#039;; use copy-assignment or copy-initialization instead\r\n}\r\n<\/pre>\n<p>Don't implement constructors for data types. Use the compiler generated ones.<\/p>\n<h2><strong id=\"padded\">-Werror=padded<\/strong><\/h2>\n<p>Warn if padding is included in a structure, either to align an element of the structure or to align the whole structure.<\/p>\n<table>\n<tr>\n<td>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct X {    \/\/ error: padding struct size to alignment boundary\r\n  int i;  \r\n  double d;   \/\/ error: padding struct to align &#039;X::d&#039;\r\n  float j;\r\n};\r\n\r\nauto func() {\r\n    return X{1, 2.0, 3.0};\r\n}\r\n<\/pre>\n<\/td>\n<td>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nfunc():\r\n        movq    .LC0(%rip), %rdx\r\n        movq    %rdi, %rax\r\n        movl    $1, (%rdi)\r\n        movl    $0x40400000, 16(%rdi)\r\n        movq    %rdx, 8(%rdi)\r\n        ret\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<p>Swap the double with the float. It create less and hence faster ASM code too.<\/p>\n<table>\n<tr>\n<td>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct X {    \r\n  int i;  \r\n  float j;\r\n  double d;  \r\n};\r\n<\/pre>\n<\/td>\n<td>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nfunc():\r\n        movsd   .LC0(%rip), %xmm0\r\n        movabsq $4611686018427387905, %rax\r\n        ret\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<h2><strong id=\"shadow\">-Werror=shadow<\/strong><\/h2>\n<p>Warn whenever a local variable or type declaration shadows another variable, parameter, type, class member, or whenever a built-in function is shadowed.<br \/>\nThis IS a good thing. See <a href=\"http:\/\/roboblog.fatal-fury.de\/?p=4024\">C++ Guns: -Wshadow for constructor arguments<\/a><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct A{\r\n    int i;         \/\/ note: shadowed declaration is here\r\n    auto func() {\r\n        int i;     \/\/ error: declaration of &#039;i&#039; shadows a member of &#039;A&#039;\r\n    }\r\n};\r\n<\/pre>\n<h2><strong id=\"pedantic\">-Werror=pedantic -pedantic-errors<\/strong><\/h2>\n<p>Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstruct A {\r\n};;         \/\/ error: extra &#039;;&#039;\r\n<\/pre>\n<p>Y0u als0 pay @tt3nti0n to t43 sp311ing rul3s. Do YOU?<\/p>\n<h2><strong id=\"nulldereference\">-Werror=null-dereference<\/strong><\/h2>\n<p>Warn if the compiler detects paths that trigger erroneous or undefined behavior due to dereferencing a null pointer. <\/p>\n<h2><strong id=\"exceptions\">-Werror=exceptions<\/strong><\/h2>\n<p>Warn about the case when an exception handler is shadowed by another handler, which can point out a wrong ordering of exception handlers<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nint main() {\r\n  try {\r\n  }\r\n  catch(std::exception&amp; ex) {     \/\/ note: for type \u2018std::exception\u2019\r\n  }\r\n  catch(std::logic_error&amp; ex) {   \/\/ error: exception of type \u2018std::logic_error\u2019 will be caught by earlier handler \r\n  }\r\n}\r\n<\/pre>\n<h2><strong id=\"catch-value\">-Werror=catch-value<\/strong><\/h2>\n<p><a href=\"https:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-exception-ref\">https:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-exception-ref<\/a><\/p>\n<p>Warn about catch handlers that do not catch via reference.<br \/>\nWith -Wcatch-value=1 (or -Wcatch-value for short) warn about polymorphic class types that are caught by value.<br \/>\nWith -Wcatch-value=2 warn about all class types that are caught by value.<br \/>\nWith -Wcatch-value=3 warn about all types that are not caught by reference. This might be overkill, because catching a \"const char*\" is then an error.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n try {\r\n   ...\r\n }\r\n catch(std::system_error ex) { \/\/  error: catching polymorphic type \u2018class std::system_error\u2019 by value\r\n }\r\n catch(std::error_code) { \/\/  error: catching type \u2018class std::error_code\u2019 by value\r\n }\r\n catch(int) {  \/\/ error: catching non-reference type \u2018int\u2019\r\n  }\r\n<\/pre>\n<h1>Debug<\/h1>\n<p>Wenn du verzweifelst:<br \/>\n<strong>-fsignaling-nans -fsanitize-undefined-trap-on-error -fsanitize=undefined,address -fsanitize=float-divide-by-zero -ffpe-trap=invalid,zero,overflow<\/strong><\/p>\n<h1>Some usefull compiler warnings which are not enabled by -Wall or -Wextra<\/h1>\n<p><strong>-Werror=inline<\/strong><br \/>\nWarn if a function that is declared as inline cannot be inlined.<\/p>\n<p><strong>-Wconversion<\/strong><br \/>\nWarn for implicit conversions that may alter a value. This includes conversions between real and integer, like abs (x) when x is double; conversions between signed and unsigned, like unsigned ui = -1; and conversions to smaller types, like sqrtf (M_PI). also warn for confusing overload resolution for user-defined conversions<\/p>\n<p><strong>-Wvector-operation-performance<\/strong><br \/>\nWarn if vector operation is not implemented via SIMD capabilities of the architecture. Mainly useful for the performance tuning. Vector operation can be implemented piecewise, which means that the scalar operation is performed on every vector element; in parallel, which means that the vector operation is implemented using scalars of wider type, which normally is more performance efficient; and as a single scalar, which means that vector fits into a scalar type. <\/p>\n<p><strong>-Weffc++<\/strong> (C++ and Objective-C++ only)<br \/>\n    Warn about violations of the following style guidelines from Scott Meyers' Effective C++ series of books:<\/p>\n<p>        Define a copy constructor and an assignment operator for classes with dynamically-allocated memory.<br \/>\n        Prefer initialization to assignment in constructors.<br \/>\n        Have operator= return a reference to *this.<br \/>\n        Don't try to return a reference when you must return an object.<br \/>\n        Distinguish between prefix and postfix forms of increment and decrement operators.<br \/>\n        Never overload &&, ||, or ,. <\/p>\n<p>    This option also enables <strong>-Wnon-virtual-dtor<\/strong>, which is also one of the effective C++ recommendations. However, the check is extended to warn about the lack of virtual destructor in accessible non-polymorphic bases classes too.<\/p>\n<p>    When selecting this option, be aware that the standard library headers do not obey all of these guidelines; use \u2018grep -v\u2019 to filter out those warnings. <\/p>\n<p><strong>-Wdouble-promotion<\/strong><br \/>\nGive a warning when a value of type float is implicitly promoted to double. CPUs with a 32-bit \u201csingle-precision\u201d floating-point unit implement float in hardware, but emulate double in software. On such a machine, doing computations using double values is much more expensive because of the overhead required for software emulation. <\/p>\n<p><strong>-Wsuggest-attribute=pure<br \/>\n-Wsuggest-attribute=const<br \/>\n-Wsuggest-attribute=noreturn<\/strong><br \/>\n    Warn about functions that might be candidates for attributes pure, const or noreturn. The compiler only warns for functions visible in other compilation units or (in the case of pure and const) if it cannot prove that the function returns normally. A function returns normally if it doesn't contain an infinite loop or return abnormally by throwing, calling abort() or trapping. This analysis requires option -fipa-pure-const, which is enabled by default at -O and higher. Higher optimization levels improve the accuracy of the analysis.<\/p>\n<p>Other Stuff<br \/>\n<strong>-fsplit-stack<\/strong><br \/>\n    Generate code to automatically split the stack before it overflows. The resulting program has a discontiguous stack which can only overflow if the program is unable to allocate any more memory. This is most useful when running threaded programs, as it is no longer necessary to calculate a good stack size to use for each thread. This is currently only implemented for the i386 and x86_64 back ends running GNU\/Linux.<\/p>\n<p>    When code compiled with -fsplit-stack calls code compiled without -fsplit-stack, there may not be much stack space available for the latter code to run. If compiling all code, including library code, with -fsplit-stack is not an option, then the linker can fix up these calls so that the code compiled without -fsplit-stack always has a large stack. Support for this is implemented in the gold linker in GNU binutils release 2.21 and later. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Check cache size cat \/sys\/devices\/system\/cpu\/cpu0\/cache\/index3\/size or lstopo https:\/\/gcc.gnu.org\/onlinedocs\/gcc\/ https:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/manual\/debug_mode.html TODO -Werror=attributes -Werror=padded -Werror=shadow -Werror=pedantic -Werror=null-dereference -Werror=exceptions -Werror=catch-value Hier die Zusammenfassung C&#038;P in eure Projekt Datei. Mit GCC Version Test { GCC_VERSION = &#x24;&#x24;system(&#x24;&#x24;QMAKE_CXX \" -dumpversion\") VERSIONS = &#x24;&#x24;split(GCC_VERSION, .) VERSION_MAJ = &#x24;&#x24;member(VERSIONS) contains(VERSION_MAJ, 12) { message( \"g++ version 12.x found\" ) CONFIG += g++12 } [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2084","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/pages\/2084","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2084"}],"version-history":[{"count":66,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/pages\/2084\/revisions"}],"predecessor-version":[{"id":5373,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/pages\/2084\/revisions\/5373"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}