[clang-tools-extra] fda7778 - [clang-tidy] Update tests to include C++23 and C++26
Adrian Vogelsgesang via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 7 14:25:34 PDT 2023
Author: Adrian Vogelsgesang
Date: 2023-08-07T21:25:22Z
New Revision: fda777849b0088ba83e28683c53c5c8321ef2558
URL: https://github.com/llvm/llvm-project/commit/fda777849b0088ba83e28683c53c5c8321ef2558
DIFF: https://github.com/llvm/llvm-project/commit/fda777849b0088ba83e28683c53c5c8321ef2558.diff
LOG: [clang-tidy] Update tests to include C++23 and C++26
This commit changes the `c++xx-or-later` definitions to also include
C++23 and the upcoming C++26.
`readability/container-contains.cpp` to also test newer C++ versions.
Also, this commit adjusts a couple of test cases slightly:
* `container-contains.cpp` now also tests newer C++ versions.
Restricting it to C++20 was an oversight of mine when originally
writing this check.
* `unconventional-assign-operator.cpp`: The `return rhs` raised
a "non-const lvalue reference to type 'BadReturnStatement' cannot
bind to a temporary" error in C++23. The issue is circumenvented
by writing `return *&rhs`.
* `const-correctness-values.cpp` was also running into the same error
in C++23. The troublesome test cases were moved to a separate file.
Differential Revision: https://reviews.llvm.org/D157246
Added:
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
Modified:
clang-tools-extra/test/clang-tidy/check_clang_tidy.py
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp
clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
index a78996a0fce3b0..53ffca0bad8d06 100755
--- a/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ b/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -265,15 +265,17 @@ def run(self):
def expand_std(std):
if std == "c++98-or-later":
- return ["c++98", "c++11", "c++14", "c++17", "c++20"]
+ return ["c++98", "c++11", "c++14", "c++17", "c++20", "c++23", "c++2c"]
if std == "c++11-or-later":
- return ["c++11", "c++14", "c++17", "c++20"]
+ return ["c++11", "c++14", "c++17", "c++20", "c++23", "c++2c"]
if std == "c++14-or-later":
- return ["c++14", "c++17", "c++20"]
+ return ["c++14", "c++17", "c++20", "c++23", "c++2c"]
if std == "c++17-or-later":
- return ["c++17", "c++20"]
+ return ["c++17", "c++20", "c++23", "c++2c"]
if std == "c++20-or-later":
- return ["c++20"]
+ return ["c++20", "c++23", "c++2c"]
+ if std == "c++23-or-later":
+ return ["c++23", "c++2c"]
return [std]
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
new file mode 100644
index 00000000000000..3547ec080911eb
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
@@ -0,0 +1,20 @@
+// RUN: %check_clang_tidy -std=c++11,c++14,c++17,c++20 %s misc-const-correctness %t -- \
+// RUN: -config="{CheckOptions: {\
+// RUN: misc-const-correctness.TransformValues: true, \
+// RUN: misc-const-correctness.WarnPointersAsValues: false, \
+// RUN: misc-const-correctness.TransformPointersAsValues: false \
+// RUN: }}" -- -fno-delayed-template-parsing
+
+
+double &non_const_ref_return() {
+ double p_local0 = 0.0;
+ // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared 'const'
+ // CHECK-FIXES: double const p_local0
+ double np_local0 = 42.42;
+ return np_local0;
+}
+
+double *&return_non_const_pointer_ref() {
+ double *np_local0 = nullptr;
+ return np_local0;
+}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 88f40462003e88..186e3cf5a179b2 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -1,9 +1,9 @@
// RUN: %check_clang_tidy %s misc-const-correctness %t -- \
// RUN: -config="{CheckOptions: {\
-// RUN: misc-const-correctness.TransformValues: true, \
-// RUN: misc-const-correctness.WarnPointersAsValues: false, \
-// RUN: misc-const-correctness.TransformPointersAsValues: false} \
-// RUN: }" -- -fno-delayed-template-parsing
+// RUN: misc-const-correctness.TransformValues: true, \
+// RUN: misc-const-correctness.WarnPointersAsValues: false, \
+// RUN: misc-const-correctness.TransformPointersAsValues: false \
+// RUN: }}" -- -fno-delayed-template-parsing
// ------- Provide test samples for primitive builtins ---------
// - every 'p_*' variable is a 'potential_const_*' variable
@@ -181,14 +181,7 @@ const double *const_pointer_return() {
return &p_local1;
}
-double &non_const_ref_return() {
- double p_local0 = 0.0;
- // CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared 'const'
- // CHECK-FIXES: double const p_local0
- double np_local0 = 42.42;
- return np_local0;
-}
-
+// Also see const-correctness-values.cpp-before-cxx23.cpp for `non_const_ref_return` and `return_non_const_pointer_ref`
const double &const_ref_return() {
double p_local0 = 0.0;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: variable 'p_local0' of type 'double' can be declared 'const'
@@ -199,11 +192,6 @@ const double &const_ref_return() {
return p_local1;
}
-double *&return_non_const_pointer_ref() {
- double *np_local0 = nullptr;
- return np_local0;
-}
-
void overloaded_arguments(const int &in);
void overloaded_arguments(int &inout);
void overloaded_arguments(const int *in);
diff --git a/clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp
index 566773ff3f5c42..74a22a7c083f4b 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp
@@ -45,7 +45,7 @@ struct BadArgument {
BadArgument& operator=(BadArgument&);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should take 'BadArgument const&', 'BadArgument&&' or 'BadArgument'
BadArgument& operator=(const BadArgument&&);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should take 'BadAr
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: operator=() should take 'BadArgument const&', 'BadArgument&&' or 'BadArgument'
};
struct BadModifier {
@@ -76,7 +76,7 @@ class BadReturnStatement {
public:
BadReturnStatement& operator=(BadReturnStatement&& rhs) {
n = std::move(rhs.n);
- return rhs;
+ return *&rhs;
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: operator=() should always return '*this'
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
index c4ea1e27e63e6f..05a4ebc9c8a177 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++20 %s readability-container-contains %t
+// RUN: %check_clang_tidy -std=c++20-or-later %s readability-container-contains %t
// Some *very* simplified versions of `map` etc.
namespace std {
More information about the cfe-commits
mailing list