================
@@ -0,0 +1,562 @@
+// RUN: %check_clang_tidy -std=c++11 -check-suffix=11 %s misc-use-constexpr %t 
-- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++14 -check-suffix=11,14 %s misc-use-constexpr 
%t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++17 -check-suffix=11,14,17 %s 
misc-use-constexpr %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++20 -check-suffix=11,14,17,20 %s 
misc-use-constexpr %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++23-or-later -check-suffix=11,14,17,20,23 %s 
misc-use-constexpr %t -- -- -fno-delayed-template-parsing
+
+// RUN: %check_clang_tidy -std=c++11 -check-suffix=11,11-CLT %s 
misc-use-constexpr %t -- -config="{CheckOptions: 
{misc-use-constexpr.ConservativeLiteralType: false}}" -- 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++14 -check-suffix=11,11-CLT,14,14-CLT %s 
misc-use-constexpr %t -- -config="{CheckOptions: 
{misc-use-constexpr.ConservativeLiteralType: false}}" -- 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++17 
-check-suffix=11,11-CLT,14,14-CLT,17,17-CLT %s misc-use-constexpr %t -- 
-config="{CheckOptions: {misc-use-constexpr.ConservativeLiteralType: false}}" 
-- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++20 
-check-suffix=11,11-CLT,14,14-CLT,17,17-CLT,20,20-CLT %s misc-use-constexpr %t 
-- -config="{CheckOptions: {misc-use-constexpr.ConservativeLiteralType: 
false}}" -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++23-or-later -check-suffix=11,14,17,20,23 %s 
misc-use-constexpr %t -- -config="{CheckOptions: 
{misc-use-constexpr.ConservativeLiteralType: false}}" -- 
-fno-delayed-template-parsing
+
+namespace {
+namespace my {
+  struct point {
+    constexpr point() {}
+    int get_x() const { return x; }
+    // CHECK-MESSAGES-11: :[[@LINE-1]]:9: warning: function 'get_x' can be 
declared 'constexpr' [misc-use-constexpr]
+    // CHECK-FIXES-11: constexpr int get_x() const { return x; }
+    int x;
+    int y;
+  };
+
+  struct point2 {
+    point2();
+    int get_x() const { return x; }
+    int x;
+  };
+} // namespace my
+} // namespace
+
+namespace function {
+  struct Empty {};
+
+  struct Base {
+    virtual void virt() = 0;
+  };
+  struct Derived : Base {
+    Derived() {}
+    void virt() override {}
+  };
+
+  static void f1() {}
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:15: warning: function 'f1' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static void f1() {}
+
+  static int f2() { return 0; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f2' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f2() { return 0; }
+
+  static int f3(int x) { return x; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f3' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f3(int x) { return x; }
+
+  static int f4(Empty x) { return 0; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f4' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f4(Empty x) { return 0; }
+
+  static int f5(Empty x) { return 0; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f5' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f5(Empty x) { return 0; }
+
+  static int f6(Empty x) { ; return 0; }
+  // CHECK-MESSAGES-14: :[[@LINE-1]]:14: warning: function 'f6' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-14: constexpr static int f6(Empty x) { ; return 0; }
+
+  static int f7(Empty x) { static_assert(0 == 0, ""); return 0; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f7' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f7(Empty x) { static_assert(0 == 0, 
""); return 0; }
+
+  static int f8(Empty x) { using my_int = int; return 0; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f8' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f8(Empty x) { using my_int = int; 
return 0; }
+
+  static int f9(Empty x) { using my::point; return 0; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f9' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f9(Empty x) { using my::point; 
return 0; }
+
+  static int f10(Empty x) { return 10; return 0; }
+  // CHECK-MESSAGES-14: :[[@LINE-1]]:14: warning: function 'f10' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-14: constexpr static int f10(Empty x) { return 10; return 0; }
+
+  static int f11(Empty x) { if (true) return 10; return 0; }
+  // CHECK-MESSAGES-14: :[[@LINE-1]]:14: warning: function 'f11' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-14: constexpr static int f11(Empty x) { if (true) return 10; 
return 0; }
+
+  static int f12(Empty x) { label: ; goto label; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f12' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f12(Empty x) { label: ; goto label; 
return 0; }
+  static int f13(Empty x) { try { throw 0; } catch(int) {}; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f13' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f13(Empty x) { try { throw 0; } 
catch(int) {}; return 0; }
+  static int f14(Empty x) { asm ("mov %rax, %rax"); }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f14' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f14(Empty x) { asm ("mov %rax, 
%rax"); }
+  static int f15(Empty x) { int y; return 0; }
+  // CHECK-MESSAGES-20: :[[@LINE-1]]:14: warning: function 'f15' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-20: constexpr static int f15(Empty x) { int y; return 0; }
+  static int f16(Empty x) { static int y = 0; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f16' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f16(Empty x) { static int y = 0; 
return 0; }
+  static int f17(Empty x) { thread_local int y = 0; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f17' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f17(Empty x) { thread_local int y = 
0; return 0; }
+  static int f18(Empty x) { [](){ label: ; goto label; return 0;  }; return 0; 
}
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f18' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f18(Empty x) { [](){ label: ; goto 
label; return 0;  }; return 0; }
+  static int f19(Empty x) { [](){ try { throw 0; } catch(int) {}; return 0;  
}; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f19' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f19(Empty x) { [](){ try { throw 0; 
} catch(int) {}; return 0;  }; return 0; }
+  static int f20(Empty x) { [](){ asm ("mov %rax, %rax");  }; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f20' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f20(Empty x) { [](){ asm ("mov %rax, 
%rax");  }; return 0; }
+  static int f21(Empty x) { [](){ int y; return 0;  }; return 0; }
+  // CHECK-MESSAGES-20: :[[@LINE-1]]:14: warning: function 'f21' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-20: constexpr static int f21(Empty x) { [](){ int y; return 
0;  }; return 0; }
+  static int f22(Empty x) { [](){ static int y = 0; return 0;  }; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f22' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f22(Empty x) { [](){ static int y = 
0; return 0;  }; return 0; }
+  static int f23(Empty x) { [](){ thread_local int y = 0; return 0;  }; return 
0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f23' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f23(Empty x) { [](){ thread_local 
int y = 0; return 0;  }; return 0; }
+
+  static int f24(Empty x) { return [](){ return 0; }(); }
+  // CHECK-MESSAGES-17: :[[@LINE-1]]:14: warning: function 'f24' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-17: constexpr static int f24(Empty x) { return [](){ return 
0; }(); }
+
+  static int f25(Empty x) { new int; return 0; }
+  // CHECK-MESSAGES-20: :[[@LINE-1]]:14: warning: function 'f25' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-20: constexpr static int f25(Empty x) { new int; return 0; }
+
+  struct Range0To10 {
+    struct iterator {
+      int operator*() const;
+      void operator++();
+      friend bool operator!=(const iterator&lhs, const iterator&rhs) { return 
lhs.i == rhs.i; }
+      int i;
+    };
+    iterator begin() const;
+    iterator end() const;
+  };
+  static int f26(Empty x) {
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f26' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f26(Empty x) {
+  // CHECK-MESSAGES-14-CLT: :[[@LINE-3]]:14: warning: function 'f26' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-14-CLT: constexpr static int f26(Empty x) {
+    auto R = Range0To10{};
+    for (const int i: R) { }
+    return 0;
+  }
+} // namespace function
+namespace function_non_literal {
+  struct NonLiteral{
+    NonLiteral();
+    ~NonLiteral();
+    int &ref;
+  };
+
+  struct Base {
+    virtual void virt() = 0;
+  };
+  struct Derived : Base {
+    Derived() {}
+    void virt() override {}
+  };
+
+  static void f1() {}
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:15: warning: function 'f1' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static void f1() {}
+
+  static int f2() { return 0; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f2' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f2() { return 0; }
+
+  static int f3(int x) { return x; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f3' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f3(int x) { return x; }
+
+  static int f4(NonLiteral x) { return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f4' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f4(NonLiteral x) { return 0; }
+
+  static int f5(NonLiteral x) { return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f5' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f5(NonLiteral x) { return 0; }
+
+  static int f6(NonLiteral x) { ; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f6' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f6(NonLiteral x) { ; return 0; }
+
+  static int f7(NonLiteral x) { static_assert(0 == 0, ""); return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f7' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f7(NonLiteral x) { static_assert(0 
== 0, ""); return 0; }
+
+  static int f8(NonLiteral x) { using my_int = int; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f8' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f8(NonLiteral x) { using my_int = 
int; return 0; }
+
+  static int f9(NonLiteral x) { using my::point; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f9' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f9(NonLiteral x) { using my::point; 
return 0; }
+
+  static int f10(NonLiteral x) { return 10; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f10' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f10(NonLiteral x) { return 10; 
return 0; }
+
+  static int f11(NonLiteral x) { if (true) return 10; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f11' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f11(NonLiteral x) { if (true) return 
10; return 0; }
+
+  static int f12(NonLiteral x) { label: ; goto label; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f12' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f12(NonLiteral x) { label: ; goto 
label; return 0; }
+  static int f13(NonLiteral x) { try { throw 0; } catch(int) {}; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f13' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f13(NonLiteral x) { try { throw 0; } 
catch(int) {}; return 0; }
+  static int f14(NonLiteral x) { asm ("mov %rax, %rax"); }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f14' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f14(NonLiteral x) { asm ("mov %rax, 
%rax"); }
+  static int f15(NonLiteral x) { int y; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f15' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f15(NonLiteral x) { int y; return 0; 
}
+  static int f16(NonLiteral x) { static int y = 0; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f16' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f16(NonLiteral x) { static int y = 
0; return 0; }
+  static int f17(NonLiteral x) { thread_local int y = 0; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f17' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f17(NonLiteral x) { thread_local int 
y = 0; return 0; }
+  static int f18(NonLiteral x) { [](){ label: ; goto label; return 0;  }; 
return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f18' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f18(NonLiteral x) { [](){ label: ; 
goto label; return 0;  }; return 0; }
+  static int f19(NonLiteral x) { [](){ try { throw 0; } catch(int) {}; return 
0;  }; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f19' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f19(NonLiteral x) { [](){ try { 
throw 0; } catch(int) {}; return 0;  }; return 0; }
+  static int f20(NonLiteral x) { [](){ asm ("mov %rax, %rax");  }; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f20' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f20(NonLiteral x) { [](){ asm ("mov 
%rax, %rax");  }; return 0; }
+  static int f21(NonLiteral x) { [](){ int y; return 0;  }; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f21' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f21(NonLiteral x) { [](){ int y; 
return 0;  }; return 0; }
+  static int f22(NonLiteral x) { [](){ static int y = 0; return 0;  }; return 
0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f22' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f22(NonLiteral x) { [](){ static int 
y = 0; return 0;  }; return 0; }
+  static int f23(NonLiteral x) { [](){ thread_local int y = 0; return 0;  }; 
return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f23' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f23(NonLiteral x) { [](){ 
thread_local int y = 0; return 0;  }; return 0; }
+
+  static int f24(NonLiteral x) { return [](){ return 0; }(); }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f24' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f24(NonLiteral x) { return [](){ 
return 0; }(); }
+
+  static int f25(NonLiteral x) { new int; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f25' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f25(NonLiteral x) { new int; return 
0; }
+
+  struct Range0To10 {
+    struct iterator {
+      int operator*() const { return i; }
+      void operator++() { ++i; }
+      friend bool operator!=(const iterator&lhs, const iterator&rhs) { return 
lhs.i == rhs.i; }
+      int i;
+    };
+    iterator begin() const { return { 0 }; }
+    iterator end() const { return { 10 }; }
+  };
+  static int f26(NonLiteral x) {
+    auto R = Range0To10{};
+    for (const int i: R) { }
+    return 0;
+  }
+  // CHECK-MESSAGES-23: :[[@LINE-5]]:14: warning: function 'f26' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f26(NonLiteral x) {
+} // namespace function_non_literal
+namespace function_non_literal_ref {
+  struct NonLiteral{
+    NonLiteral();
+    ~NonLiteral();
+    int &ref;
+  };
+
+  struct Base {
+    virtual void virt() = 0;
+  };
+  struct Derived : Base {
+    Derived() {}
+    void virt() override {}
+  };
+
+  static void f1() {}
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:15: warning: function 'f1' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static void f1() {}
+
+  static int f2() { return 0; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f2' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f2() { return 0; }
+
+  static int f3(int x) { return x; }
+  // CHECK-MESSAGES-11: :[[@LINE-1]]:14: warning: function 'f3' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11: constexpr static int f3(int x) { return x; }
+
+  static int f4(NonLiteral& x) { return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f4' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f4(NonLiteral& x) { return 0; }
+  // CHECK-MESSAGES-11-CLT: :[[@LINE-3]]:14: warning: function 'f4' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11-CLT: constexpr static int f4(NonLiteral& x) { return 0; }
+
+  static int f5(NonLiteral& x) { return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f5' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f5(NonLiteral& x) { return 0; }
+  // CHECK-MESSAGES-11-CLT: :[[@LINE-3]]:14: warning: function 'f5' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11-CLT: constexpr static int f5(NonLiteral& x) { return 0; }
+
+  static int f6(NonLiteral& x) { ; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f6' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f6(NonLiteral& x) { ; return 0; }
+  // CHECK-MESSAGES-14-CLT: :[[@LINE-3]]:14: warning: function 'f6' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-14-CLT: constexpr static int f6(NonLiteral& x) { ; return 0; }
+
+  static int f7(NonLiteral& x) { static_assert(0 == 0, ""); return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f7' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f7(NonLiteral& x) { static_assert(0 
== 0, ""); return 0; }
+  // CHECK-MESSAGES-11-CLT: :[[@LINE-3]]:14: warning: function 'f7' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11-CLT: constexpr static int f7(NonLiteral& x) { 
static_assert(0 == 0, ""); return 0; }
+
+  static int f8(NonLiteral& x) { using my_int = int; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f8' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f8(NonLiteral& x) { using my_int = 
int; return 0; }
+  // CHECK-MESSAGES-11-CLT: :[[@LINE-3]]:14: warning: function 'f8' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11-CLT: constexpr static int f8(NonLiteral& x) { using my_int 
= int; return 0; }
+
+  static int f9(NonLiteral& x) { using my::point; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f9' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f9(NonLiteral& x) { using my::point; 
return 0; }
+  // CHECK-MESSAGES-11-CLT: :[[@LINE-3]]:14: warning: function 'f9' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-11-CLT: constexpr static int f9(NonLiteral& x) { using 
my::point; return 0; }
+
+  static int f10(NonLiteral& x) { return 10; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f10' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f10(NonLiteral& x) { return 10; 
return 0; }
+  // CHECK-MESSAGES-14-CLT: :[[@LINE-3]]:14: warning: function 'f10' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-14-CLT: constexpr static int f10(NonLiteral& x) { return 10; 
return 0; }
+
+  static int f11(NonLiteral& x) { if (true) return 10; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f11' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f11(NonLiteral& x) { if (true) 
return 10; return 0; }
+  // CHECK-MESSAGES-14-CLT: :[[@LINE-3]]:14: warning: function 'f11' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-14-CLT: constexpr static int f11(NonLiteral& x) { if (true) 
return 10; return 0; }
+
+  static int f12(NonLiteral& x) { label: ; goto label; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f12' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f12(NonLiteral& x) { label: ; goto 
label; return 0; }
+  static int f13(NonLiteral& x) { try { throw 0; } catch(int) {}; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f13' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f13(NonLiteral& x) { try { throw 0; 
} catch(int) {}; return 0; }
+  static int f14(NonLiteral& x) { asm ("mov %rax, %rax"); }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f14' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f14(NonLiteral& x) { asm ("mov %rax, 
%rax"); }
+  static int f15(NonLiteral& x) { int y; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f15' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f15(NonLiteral& x) { int y; return 
0; }
+  // CHECK-MESSAGES-20-CLT: :[[@LINE-3]]:14: warning: function 'f15' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-20-CLT: constexpr static int f15(NonLiteral& x) { int y; 
return 0; }
+  static int f16(NonLiteral& x) { static int y = 0; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f16' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f16(NonLiteral& x) { static int y = 
0; return 0; }
+  static int f17(NonLiteral& x) { thread_local int y = 0; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f17' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f17(NonLiteral& x) { thread_local 
int y = 0; return 0; }
+  static int f18(NonLiteral& x) { [](){ label: ; goto label; return 0;  }; 
return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f18' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f18(NonLiteral& x) { [](){ label: ; 
goto label; return 0;  }; return 0; }
+  static int f19(NonLiteral& x) { [](){ try { throw 0; } catch(int) {}; return 
0;  }; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f19' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f19(NonLiteral& x) { [](){ try { 
throw 0; } catch(int) {}; return 0;  }; return 0; }
+  static int f20(NonLiteral& x) { [](){ asm ("mov %rax, %rax");  }; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f20' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f20(NonLiteral& x) { [](){ asm ("mov 
%rax, %rax");  }; return 0; }
+  static int f21(NonLiteral& x) { [](){ int y; return 0;  }; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f21' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f21(NonLiteral& x) { [](){ int y; 
return 0;  }; return 0; }
+  // CHECK-MESSAGES-20-CLT: :[[@LINE-3]]:14: warning: function 'f21' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-20-CLT: constexpr static int f21(NonLiteral& x) { [](){ int 
y; return 0;  }; return 0; }
+  static int f22(NonLiteral& x) { [](){ static int y = 0; return 0;  }; return 
0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f22' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f22(NonLiteral& x) { [](){ static 
int y = 0; return 0;  }; return 0; }
+  static int f23(NonLiteral& x) { [](){ thread_local int y = 0; return 0;  }; 
return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f23' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f23(NonLiteral& x) { [](){ 
thread_local int y = 0; return 0;  }; return 0; }
+
+  static int f24(NonLiteral& x) { return [](){ return 0; }(); }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f24' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f24(NonLiteral& x) { return [](){ 
return 0; }(); }
+  // CHECK-MESSAGES-17-CLT: :[[@LINE-3]]:14: warning: function 'f24' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-17-CLT: constexpr static int f24(NonLiteral& x) { return 
[](){ return 0; }(); }
+
+  static int f25(NonLiteral& x) { new int; return 0; }
+  // CHECK-MESSAGES-23: :[[@LINE-1]]:14: warning: function 'f25' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f25(NonLiteral& x) { new int; return 
0; }
+  // CHECK-MESSAGES-20-CLT: :[[@LINE-3]]:14: warning: function 'f25' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-20-CLT: constexpr static int f25(NonLiteral& x) { new int; 
return 0; }
+
+  struct Range0To10 {
+    struct iterator {
+      int operator*() const { return i; }
+      void operator++() { ++i; }
+      friend bool operator!=(const iterator&lhs, const iterator&rhs) { return 
lhs.i == rhs.i; }
+      int i;
+    };
+    iterator begin() const { return { 0 }; }
+    iterator end() const { return { 10 }; }
+  };
+  static int f26(NonLiteral& x) {
+    auto R = Range0To10{};
+    for (const int i: R) { }
+    return 0;
+  }
+  // CHECK-MESSAGES-23: :[[@LINE-5]]:14: warning: function 'f26' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-23: constexpr static int f26(NonLiteral& x) {
+  // CHECK-MESSAGES-14-CLT: :[[@LINE-7]]:14: warning: function 'f26' can be 
declared 'constexpr' [misc-use-constexpr]
+  // CHECK-FIXES-14-CLT: constexpr static int f26(NonLiteral& x) {
+} // namespace function_non_literal_ref
+
+namespace {
+namespace variable {
+    namespace literal_type {
+        constexpr int f1() { return 0; }
+        int g1() { return 0; }
+        // CHECK-MESSAGES-11: :[[@LINE-1]]:13: warning: function 'g1' can be 
declared 'constexpr' [misc-use-constexpr]
+        // CHECK-FIXES-11: constexpr int g1() { return 0; }
+        static constexpr int A1 = 0;
+        static int B1 = 0;
----------------
5chmidti wrote:

I will extend the check docs to explain the dependency on `const` for variables.

https://github.com/llvm/llvm-project/pull/146553
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to