avogelsgesang created this revision. Herald added subscribers: PiotrZSL, carlosgalvezp, xazax.hun. Herald added a project: All. avogelsgesang requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
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. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D157246 Files: clang-tools-extra/test/clang-tidy/check_clang_tidy.py clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp 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
Index: clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability/container-contains.cpp +++ 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 { Index: clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp +++ clang-tools-extra/test/clang-tidy/checkers/misc/unconventional-assign-operator.cpp @@ -45,7 +45,7 @@ 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 @@ 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' } Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp +++ clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp @@ -181,14 +181,7 @@ 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 @@ 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); Index: clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp =================================================================== --- /dev/null +++ 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: {key: 'misc-const-correctness.TransformValues', value: true}, \ +// RUN: {key: 'misc-const-correctness.WarnPointersAsValues', value: false}, \ +// RUN: {key: 'misc-const-correctness.TransformPointersAsValues', value: 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; +} Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py =================================================================== --- clang-tools-extra/test/clang-tidy/check_clang_tidy.py +++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py @@ -265,15 +265,17 @@ 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]
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits