diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-24 21:08:12 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-05-24 21:08:12 +0000 |
commit | de47d66191e50e8a741ed551c25d60bbf86da5e4 (patch) | |
tree | fc4cb41f2a64be93bedaf8d02b21b922ab3f2638 /clang/test/SemaCXX/default1.cpp | |
parent | 8e1d921bb37c57e75660e259f5751797c5bd0d9d (diff) | |
download | bcm5719-llvm-de47d66191e50e8a741ed551c25d60bbf86da5e4.tar.gz bcm5719-llvm-de47d66191e50e8a741ed551c25d60bbf86da5e4.zip |
Default arguments are potentially constant evaluated.
We need to eagerly instantiate constexpr functions used in them even if
the default argument is never actually used, because we might evaluate
portions of it when performing semantic checks.
llvm-svn: 361670
Diffstat (limited to 'clang/test/SemaCXX/default1.cpp')
-rw-r--r-- | clang/test/SemaCXX/default1.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/default1.cpp b/clang/test/SemaCXX/default1.cpp index fcaa2c839d6..3bc6f832b68 100644 --- a/clang/test/SemaCXX/default1.cpp +++ b/clang/test/SemaCXX/default1.cpp @@ -78,3 +78,21 @@ void PR20769(int = 2); void PR20769_b(int = 1); void PR20769_b() { void PR20769_b(int = 2); } + +#if __cplusplus >= 201103L +template<typename T> constexpr int f1() { return 0; } +// This is OK, but in order to see that we must instantiate f<int>, despite it +// being in an unused default argument. +void g1(char c = {f1<int>()}) {} // expected-warning {{braces around scalar}} + +// This is formally ill-formed, but we choose to not trigger instantiation here +// (at least, not until g2 is actually called in a way that uses the default +// argument). +template<typename T> int f2() { return T::error; } +void g2(int c = f2<int>()) {} + +// FIXME: Provide a note pointing at the first use of the default argument? +template<typename T> int f3() { return T::error; } // expected-error {{no members}} +void g3(int c = f3<int>()) {} // expected-note {{in instantiation of}} +void use_g3() { g3(); } +#endif |