================ @@ -0,0 +1,170 @@ +// RUN: %clang %s -std=c++17 -Xclang -verify --analyze \ +// RUN: -Xclang -analyzer-checker=core \ +// RUN: -Xclang -analyzer-checker=debug.ExprInspection \ +// RUN: -Xclang -analyzer-checker=core,alpha.core.StdAny + +#include "Inputs/system-header-simulator-cxx.h" + +void clang_analyzer_warnIfReached(); +void clang_analyzer_eval(int); + + +class DummyClass{ + public: + void foo(){}; +}; + +void nonInlined(std::any &a); +void nonInlinedConst(const std::any & a); + +void inlined(std::any &a) { + a = 5; +} + +using any_t = std::any; +using any_tt = any_t; + + +//----------------------------------------------------------------------------// +// std::any_cast +//----------------------------------------------------------------------------// +void objectHeld() { + std::any a = DummyClass{}; + DummyClass d = std::any_cast<DummyClass>(a); + d.foo(); +} + +void formVariable() { + std::any a = 5; + int b = std::any_cast<int>(a); + char c = std::any_cast<char>(a); // expected-warning {{std::any 'a' held an 'int', not a 'char'}} + (void)b; + (void)c; +} + +void pointerHeld() { + int i = 5; + std::any a = &i; + int* x = std::any_cast<int*>(a); + char c = std::any_cast<char>(a); // expected-warning {{std::any 'a' held an 'int *', not a 'char'}} ---------------- whisperity wrote:
(Yeah, back to the vowel/pronounciation stuff, this reads correctly if you say `held an «int star»` but breaks apart if one meticulously wants to read this out as `held an «pointer to int object»`...) https://github.com/llvm/llvm-project/pull/76580 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits