diff options
| author | Erich Keane <erich.keane@intel.com> | 2017-09-18 21:28:55 +0000 |
|---|---|---|
| committer | Erich Keane <erich.keane@intel.com> | 2017-09-18 21:28:55 +0000 |
| commit | 0ac9524c9924636834f8a2058e81e95f334c440d (patch) | |
| tree | 98c2fdc7632b0f1a49c61315879c2c4437d98202 | |
| parent | 283eae82fd46bf9036fb331d878dcceff80014a9 (diff) | |
| download | bcm5719-llvm-0ac9524c9924636834f8a2058e81e95f334c440d.tar.gz bcm5719-llvm-0ac9524c9924636834f8a2058e81e95f334c440d.zip | |
[Sema] Fix a pair of crashes when generating exception specifiers with an
error'ed field for a template class' default ctor.
The two examples in the test would both cause a compiler assert when attempting
to calculate the exception specifier for the default constructor for the
template classes. The problem was that dependents of this function expect that
Field->getInClassInitializer (including canThrow) is not nullptr. However, if
the template's initializer has an error, exactly that situation happens.
This patch simply sets the field to be invalid.
Differential Revision: https://reviews.llvm.org/D37865
llvm-svn: 313569
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 3 | ||||
| -rw-r--r-- | clang/test/SemaCXX/init-expr-crash.cpp | 31 |
2 files changed, 33 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index a9ef333c66e..529084a517b 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -12436,7 +12436,8 @@ ExprResult Sema::BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field) { assert(Pattern && "We must have set the Pattern!"); } - if (InstantiateInClassInitializer(Loc, Field, Pattern, + if (!Pattern->hasInClassInitializer() || + InstantiateInClassInitializer(Loc, Field, Pattern, getTemplateInstantiationArgs(Field))) { // Don't diagnose this again. Field->setInvalidDecl(); diff --git a/clang/test/SemaCXX/init-expr-crash.cpp b/clang/test/SemaCXX/init-expr-crash.cpp new file mode 100644 index 00000000000..407da78e60b --- /dev/null +++ b/clang/test/SemaCXX/init-expr-crash.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11 + +// Test reproduces a pair of crashes that were caused by code attempting +// to materialize a default constructor's exception specifier. + +template <class T> struct A { + static T tab[]; + + const int M = UNDEFINED; // expected-error {{use of undeclared identifier}} + + int main() + { + A<char> a; + + return 0; + } +}; + +template <class T> struct B { + static T tab[]; + + // expected-error@+1 {{invalid application of 'sizeof' to an incomplete type}} + const int N = sizeof(B<char>::tab) / sizeof(char); + + int main() + { + B<char> b; + + return 0; + } +}; |

