diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2012-02-02 23:15:15 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2012-02-02 23:15:15 +0000 |
commit | 3bda6b1f8e2076955990031f8155025a40f8eea9 (patch) | |
tree | 0d0241ca3101a620641ce7fb2400595617ffd899 /clang/test/SemaCXX/undefined-internal.cpp | |
parent | caed1c9370dd492894c655cf7eb7567a6f1887d0 (diff) | |
download | bcm5719-llvm-3bda6b1f8e2076955990031f8155025a40f8eea9.tar.gz bcm5719-llvm-3bda6b1f8e2076955990031f8155025a40f8eea9.zip |
Add some code to accurately perform odr-used marking for variables per the C++11 rules.
llvm-svn: 149641
Diffstat (limited to 'clang/test/SemaCXX/undefined-internal.cpp')
-rw-r--r-- | clang/test/SemaCXX/undefined-internal.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/undefined-internal.cpp b/clang/test/SemaCXX/undefined-internal.cpp index e926f18d5ff..6fe64b8ceda 100644 --- a/clang/test/SemaCXX/undefined-internal.cpp +++ b/clang/test/SemaCXX/undefined-internal.cpp @@ -122,3 +122,48 @@ namespace PR9323 { f(Uncopyable()); // expected-warning {{C++98 requires an accessible copy constructor}} }; } + + +namespace std { class type_info; }; +namespace cxx11_odr_rules { + // Note: the way this test is written isn't really ideal, but there really + // isn't any other way to check that the odr-used logic for constants + // is working without working implicit capture in lambda-expressions. + // (The more accurate used-but-not-defined warning is the only other visible + // effect of accurate odr-used computation.) + // + // Note that the warning in question can trigger in cases some people would + // consider false positives; hopefully that happens rarely in practice. + + namespace { + struct A { + static const int unused = 10; + static const int used1 = 20; // expected-warning {{internal linkage}} + static const int used2 = 20; // expected-warning {{internal linkage}} + virtual ~A() {} + }; + } + + void a(int,int); + A& p(const int&) { static A a; return a; } + + // Check handling of default arguments + void b(int = A::unused); + + void tests() { + // Basic test + a(A::unused, A::unused); + + // Check that nesting an unevaluated or constant-evaluated context does + // the right thing. + a(A::unused, sizeof(int[10])); + + // Check that the checks work with unevaluated contexts + (void)sizeof(p(A::used1)); + (void)typeid(p(A::used1)); // expected-note {{used here}} + + // Misc other testing + a(A::unused, 1 ? A::used2 : A::used2); // expected-note {{used here}} + b(); + } +} |