[PATCH] D20463: [clang-tidy] Add more descriptive comments and examples in misc-definitions-in-headers check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri May 20 02:12:37 PDT 2016


hokein created this revision.
hokein added a reviewer: alexfh.
hokein added a subscriber: cfe-commits.

http://reviews.llvm.org/D20463

Files:
  docs/clang-tidy/checks/misc-definitions-in-headers.rst

Index: docs/clang-tidy/checks/misc-definitions-in-headers.rst
===================================================================
--- docs/clang-tidy/checks/misc-definitions-in-headers.rst
+++ docs/clang-tidy/checks/misc-definitions-in-headers.rst
@@ -4,36 +4,71 @@
 Finds non-extern non-inline function and variable definitions in header files,
 which can lead to potential ODR violations.
 
+If these headers are included from multiple translation units, there will be
+redefinition linker errors.
+
 .. code:: c++
 
    // Foo.h
-   int a = 1; // Warning.
+   int a = 1; // Warning: variable definition.
    extern int d; // OK: extern variable.
 
    namespace N {
-     int e = 2; // Warning.
+     int e = 2; // Warning: variable definition.
    }
 
-   // Internal linkage variable definitions are ignored for now.
+   // Warning: variable definition.
+   const char* str = "foo";
+
+   // OK: internal linkage variable definitions are ignored for now.
    // Although these might also cause ODR violations, we can be less certain and
    // should try to keep the false-positive rate down.
    static int b = 1;
    const int c = 1;
+   const char* const str2 = "foo";
 
-   // Warning.
+   // Warning: function definition.
    int g() {
      return 1;
    }
 
-   // OK: inline function definition.
+   // OK: inline function definition is allowed to be multiply defined.
    inline int e() {
      return 1;
    }
 
    class A {
     public:
-     int f1() { return 1; } // OK: inline member function definition.
+     int f1() { return 1; } // OK: implicitly inline member function definition is allowed.
      int f2();
+     static int d;
+   };
+
+   // Warning: not a inline member function definition.
+   int A::f2() { return 1; }
+
+   // OK: class static data member declaration is allowed.
+   int A::d = 1;
+
+   // OK: funtion template is allowed.
+   template<typename T>
+   T f3() {
+     T a = 1;
+     return a;
+   }
+
+   // Warning: full function template specialization is not allowed.
+   template <>
+   int f3() {
+     int a = 1;
+     return a;
+   }
+
+   template <typename T>
+   struct B {
+     void f1();
    };
 
-   int A::f2() { return 1; } // Warning.
+   // OK: Member function definition of a class template is allowed.
+   template <typename T>
+   void B<T>::f1() {}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20463.57908.patch
Type: text/x-patch
Size: 2319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160520/c0b39681/attachment.bin>


More information about the cfe-commits mailing list