专业的编程技术博客社区

网站首页 > 博客文章 正文

跟老韩学Ubuntu Server 2204-gcc指令帮助手册09节

baijin 2024-09-12 11:06:50 博客文章 12 ℃ 0 评论

GCC是每个从事Linux,以及嵌入式开发等必备的编译器,由于帮助手册较多,这里使用了分页的形式进行分享,如下为Ubuntu Server 22.04操作系统平台和GCC编译器的基本信息。

GCC帮助手册的第9小节,第1688~1888行。

1688                      };
1689              The compiler rearranges the member initializers for "i" and "j" to match the declaration order of the
1690              members, emitting a warning to that effect.  This warning is enabled by -Wall.
1691          -Wno-pessimizing-move (C++ and Objective-C++ only)
1692              This warning warns when a call to "std::move" prevents copy elision.  A typical scenario when copy elision
1693              can occur is when returning in a function with a class return type, when the expression being returned is
1694              the name of a non-volatile automatic object, and is not a function parameter, and has the same type as the
1695              function return type.
1696                      struct T {
1697                      ...
1698                      };
1699                      T fn()
1700                      {
1701                        T t;
1702                        ...
1703                        return std::move (t);
1704                      }
1705              But in this example, the "std::move" call prevents copy elision.
1706              This warning is enabled by -Wall.
1707          -Wno-redundant-move (C++ and Objective-C++ only)
1708              This warning warns about redundant calls to "std::move"; that is, when a move operation would have been
1709              performed even without the "std::move" call.  This happens because the compiler is forced to treat the
1710              object as if it were an rvalue in certain situations such as returning a local variable, where copy elision
1711              isn't applicable.  Consider:
1712                      struct T {
1713                      ...
1714                      };
1715                      T fn(T t)
1716                      {
1717                        ...
1718                        return std::move (t);
1719                      }
1720              Here, the "std::move" call is redundant.  Because G++ implements Core Issue 1579, another example is:
1721                      struct T { // convertible to U
1722                      ...
1723                      };
1724                      struct U {
1725                      ...
1726                      };
1727                      U fn()
1728                      {
1729                        T t;
1730                        ...
1731                        return std::move (t);
1732                      }
1733              In this example, copy elision isn't applicable because the type of the expression being returned and the
1734              function return type differ, yet G++ treats the return value as if it were designated by an rvalue.
1735              This warning is enabled by -Wextra.
1736          -Wrange-loop-construct (C++ and Objective-C++ only)
1737              This warning warns when a C++ range-based for-loop is creating an unnecessary copy.  This can happen when
1738              the range declaration is not a reference, but probably should be.  For example:
1739                      struct S { char arr[128]; };
1740                      void fn () {
1741                        S arr[5];
1742                        for (const auto x : arr) { ... }
1743                      }
1744              It does not warn when the type being copied is a trivially-copyable type whose size is less than 64 bytes.
1745              This warning also warns when a loop variable in a range-based for-loop is initialized with a value of a
1746              different type resulting in a copy.  For example:
1747                      void fn() {
1748                        int arr[10];
1749                        for (const double &x : arr) { ... }
1750                      }
1751              In the example above, in every iteration of the loop a temporary value of type "double" is created and
1752              destroyed, to which the reference "const double &" is bound.
1753              This warning is enabled by -Wall.
1754          -Wredundant-tags (C++ and Objective-C++ only)
1755              Warn about redundant class-key and enum-key in references to class types and enumerated types in contexts
1756              where the key can be eliminated without causing an ambiguity.  For example:
1757                      struct foo;
1758                      struct foo *p;   // warn that keyword struct can be eliminated
1759              On the other hand, in this example there is no warning:
1760                      struct foo;
1761                      void foo ();   // "hides" struct foo
1762                      void bar (struct foo&);  // no warning, keyword struct is necessary
1763          -Wno-subobject-linkage (C++ and Objective-C++ only)
1764              Do not warn if a class type has a base or a field whose type uses the anonymous namespace or depends on a
1765              type with no linkage.  If a type A depends on a type B with no or internal linkage, defining it in multiple
1766              translation units would be an ODR violation because the meaning of B is different in each translation unit.
1767              If A only appears in a single translation unit, the best way to silence the warning is to give it internal
1768              linkage by putting it in an anonymous namespace as well.  The compiler doesn't give this warning for types
1769              defined in the main .C file, as those are unlikely to have multiple definitions.  -Wsubobject-linkage is
1770              enabled by default.
1771          -Weffc++ (C++ and Objective-C++ only)
1772              Warn about violations of the following style guidelines from Scott Meyers' Effective C++ series of books:
1773              *   Define a copy constructor and an assignment operator for classes with dynamically-allocated memory.
1774              *   Prefer initialization to assignment in constructors.
1775              *   Have "operator=" return a reference to *this.
1776              *   Don't try to return a reference when you must return an object.
1777              *   Distinguish between prefix and postfix forms of increment and decrement operators.
1778              *   Never overload "&&", "||", or ",".
1779              This option also enables -Wnon-virtual-dtor, which is also one of the effective C++ recommendations.
1780              However, the check is extended to warn about the lack of virtual destructor in accessible non-polymorphic
1781              bases classes too.
1782              When selecting this option, be aware that the standard library headers do not obey all of these guidelines;
1783              use grep -v to filter out those warnings.
1784          -Wno-exceptions (C++ and Objective-C++ only)
1785              Disable the warning about the case when an exception handler is shadowed by another handler, which can
1786              point out a wrong ordering of exception handlers.
1787          -Wstrict-null-sentinel (C++ and Objective-C++ only)
1788              Warn about the use of an uncasted "NULL" as sentinel.  When compiling only with GCC this is a valid
1789              sentinel, as "NULL" is defined to "__null".  Although it is a null pointer constant rather than a null
1790              pointer, it is guaranteed to be of the same size as a pointer.  But this use is not portable across
1791              different compilers.
1792          -Wno-non-template-friend (C++ and Objective-C++ only)
1793              Disable warnings when non-template friend functions are declared within a template.  In very old versions
1794              of GCC that predate implementation of the ISO standard, declarations such as friend int foo(int), where the
1795              name of the friend is an unqualified-id, could be interpreted as a particular specialization of a template
1796              function; the warning exists to diagnose compatibility problems, and is enabled by default.
1797          -Wold-style-cast (C++ and Objective-C++ only)
1798              Warn if an old-style (C-style) cast to a non-void type is used within a C++ program.  The new-style casts
1799              ("dynamic_cast", "static_cast", "reinterpret_cast", and "const_cast") are less vulnerable to unintended
1800              effects and much easier to search for.
1801          -Woverloaded-virtual (C++ and Objective-C++ only)
1802              Warn when a function declaration hides virtual functions from a base class.  For example, in:
1803                      struct A {
1804                        virtual void f();
1805                      };
1806                      struct B: public A {
1807                        void f(int);
1808                      };
1809              the "A" class version of "f" is hidden in "B", and code like:
1810                      B* b;
1811                      b->f();
1812              fails to compile.
1813          -Wno-pmf-conversions (C++ and Objective-C++ only)
1814              Disable the diagnostic for converting a bound pointer to member function to a plain pointer.
1815          -Wsign-promo (C++ and Objective-C++ only)
1816              Warn when overload resolution chooses a promotion from unsigned or enumerated type to a signed type, over a
1817              conversion to an unsigned type of the same size.  Previous versions of G++ tried to preserve unsignedness,
1818              but the standard mandates the current behavior.
1819          -Wtemplates (C++ and Objective-C++ only)
1820              Warn when a primary template declaration is encountered.  Some coding rules disallow templates, and this
1821              may be used to enforce that rule.  The warning is inactive inside a system header file, such as the STL, so
1822              one can still use the STL.  One may also instantiate or specialize templates.
1823          -Wno-mismatched-new-delete (C++ and Objective-C++ only)
1824              Warn for mismatches between calls to "operator new" or "operator delete" and the corresponding call to the
1825              allocation or deallocation function.  This includes invocations of C++ "operator delete" with pointers
1826              returned from either mismatched forms of "operator new", or from other functions that allocate objects for
1827              which the "operator delete" isn't a suitable deallocator, as well as calls to other deallocation functions
1828              with pointers returned from "operator new" for which the deallocation function isn't suitable.
1829              For example, the "delete" expression in the function below is diagnosed because it doesn't match the array
1830              form of the "new" expression the pointer argument was returned from.  Similarly, the call to "free" is also
1831              diagnosed.
1832                      void f ()
1833                      {
1834                        int *a = new int[n];
1835                        delete a;   // warning: mismatch in array forms of expressions
1836                        char *p = new char[n];
1837                        free (p);   // warning: mismatch between new and free
1838                      }
1839              The related option -Wmismatched-dealloc diagnoses mismatches involving allocation and deallocation
1840              functions other than "operator new" and "operator delete".
1841              -Wmismatched-new-delete is enabled by default.
1842          -Wmismatched-tags (C++ and Objective-C++ only)
1843              Warn for declarations of structs, classes, and class templates and their specializations with a class-key
1844              that does not match either the definition or the first declaration if no definition is provided.
1845              For example, the declaration of "struct Object" in the argument list of "draw" triggers the warning.  To
1846              avoid it, either remove the redundant class-key "struct" or replace it with "class" to match its
1847              definition.
1848                      class Object {
1849                      public:
1850                        virtual ~Object () = 0;
1851                      };
1852                      void draw (struct Object*);
1853              It is not wrong to declare a class with the class-key "struct" as the example above shows.  The
1854              -Wmismatched-tags option is intended to help achieve a consistent style of class declarations.  In code
1855              that is intended to be portable to Windows-based compilers the warning helps prevent unresolved references
1856              due to the difference in the mangling of symbols declared with different class-keys.  The option can be
1857              used either on its own or in conjunction with -Wredundant-tags.
1858          -Wmultiple-inheritance (C++ and Objective-C++ only)
1859              Warn when a class is defined with multiple direct base classes.  Some coding rules disallow multiple
1860              inheritance, and this may be used to enforce that rule.  The warning is inactive inside a system header
1861              file, such as the STL, so one can still use the STL.  One may also define classes that indirectly use
1862              multiple inheritance.
1863          -Wvirtual-inheritance
1864              Warn when a class is defined with a virtual direct base class.  Some coding rules disallow multiple
1865              inheritance, and this may be used to enforce that rule.  The warning is inactive inside a system header
1866              file, such as the STL, so one can still use the STL.  One may also define classes that indirectly use
1867              virtual inheritance.
1868          -Wno-virtual-move-assign
1869              Suppress warnings about inheriting from a virtual base with a non-trivial C++11 move assignment operator.
1870              This is dangerous because if the virtual base is reachable along more than one path, it is moved multiple
1871              times, which can mean both objects end up in the moved-from state.  If the move assignment operator is
1872              written to avoid moving from a moved-from object, this warning can be disabled.
1873          -Wnamespaces
1874              Warn when a namespace definition is opened.  Some coding rules disallow namespaces, and this may be used to
1875              enforce that rule.  The warning is inactive inside a system header file, such as the STL, so one can still
1876              use the STL.  One may also use using directives and qualified names.
1877          -Wno-terminate (C++ and Objective-C++ only)
1878              Disable the warning about a throw-expression that will immediately result in a call to "terminate".
1879          -Wno-vexing-parse (C++ and Objective-C++ only)
1880              Warn about the most vexing parse syntactic ambiguity.  This warns about the cases when a declaration looks
1881              like a variable definition, but the C++ language requires it to be interpreted as a function declaration.
1882              For instance:
1883                      void f(double a) {
1884                        int i();        // extern int i (void);
1885                        int n(int(a));  // extern int n (int);
1886                      }

加油,做最好的自己。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表