Author: isuckatcs Date: 2022-10-20T14:14:52+02:00 New Revision: ea8aebf9eb7f0762d357e02524be9f65cfdb4f58
URL: https://github.com/llvm/llvm-project/commit/ea8aebf9eb7f0762d357e02524be9f65cfdb4f58 DIFF: https://github.com/llvm/llvm-project/commit/ea8aebf9eb7f0762d357e02524be9f65cfdb4f58.diff LOG: [analyzer] Move unexecuted test block into it's own source file Inside lambdas.cpp a block of code wasn't executed, because it required the standard to be at least c++14. This patch moves this block of code into it's own source file and makes sure it's tested. Differential Revision: https://reviews.llvm.org/D135965 Added: clang/test/Analysis/lambdas-modern.cpp Modified: clang/test/Analysis/lambdas.cpp Removed: ################################################################################ diff --git a/clang/test/Analysis/lambdas-modern.cpp b/clang/test/Analysis/lambdas-modern.cpp new file mode 100644 index 0000000000000..ce75acf087174 --- /dev/null +++ b/clang/test/Analysis/lambdas-modern.cpp @@ -0,0 +1,28 @@ +// RUN: %clang_analyze_cc1 -std=c++14 -analyzer-checker=core,debug.ExprInspection -analyzer-config inline-lambdas=true -verify %s +// RUN: %clang_analyze_cc1 -std=c++17 -analyzer-checker=core,debug.ExprInspection -analyzer-config inline-lambdas=true -verify %s + +#include "Inputs/system-header-simulator-cxx.h" + +void clang_analyzer_warnIfReached(); +void clang_analyzer_eval(int); + +// Capture copy elided object. +struct Elided{ + int x = 14; + Elided(int) {} +}; + +void testCopyElidedObjectCaptured(int x) { + int r = [e = Elided(x)] { + return e.x; + }(); + + clang_analyzer_eval(r == 14); // expected-warning{{TRUE}} +} + +static auto MakeUniquePtr() { return std::make_unique<std::vector<int>>(); } + +void testCopyElidedUniquePtr() { + [uniquePtr = MakeUniquePtr()] {}(); + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} +} diff --git a/clang/test/Analysis/lambdas.cpp b/clang/test/Analysis/lambdas.cpp index b1d9784dcc0bf..f86a6d472226e 100644 --- a/clang/test/Analysis/lambdas.cpp +++ b/clang/test/Analysis/lambdas.cpp @@ -205,29 +205,6 @@ void testVariableLengthArrayCaptured() { clang_analyzer_eval(i == 7); // expected-warning{{TRUE}} } -#if __cplusplus >= 201402L -// Capture copy elided object. - -struct Elided{ - int x = 0; - Elided(int) {} -}; - -void testCopyElidedObjectCaptured(int x) { - [e = Elided(x)] { - clang_analyzer_eval(e.x == 0); // expected-warning{{TRUE}} - }(); -} - -static auto MakeUniquePtr() { return std::make_unique<std::vector<int>>(); } - -void testCopyElidedUniquePtr() { - [uniquePtr = MakeUniquePtr()] {}(); - clang_analyzer_warnIfReached(); // expected-warning{{TRUE}} -} - -#endif - // Test inline defensive checks int getNum(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits