]> granicus.if.org Git - clang/commitdiff
[Sema] Fix a structured binding typo correction bug
authorErik Pilkington <erik.pilkington@gmail.com>
Tue, 10 Jul 2018 02:15:07 +0000 (02:15 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Tue, 10 Jul 2018 02:15:07 +0000 (02:15 +0000)
BindingDecls have null type until their initializer is processed, so we can't
assume that a correction candidate has non-null type.

rdar://41559582

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336634 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLookup.cpp
test/SemaCXX/typo-correction-cxx17.cpp [new file with mode: 0644]

index 984247bacc6ebcc5439bab160dae9c18e47fae3a..4545bf9d855fcad018663b9769f848af9dfca869 100644 (file)
@@ -4990,6 +4990,8 @@ bool FunctionCallFilterCCC::ValidateCandidate(const TypoCorrection &candidate) {
         // determine if it is a pointer or reference to a function. If so,
         // check against the number of arguments expected for the pointee.
         QualType ValType = cast<ValueDecl>(ND)->getType();
+        if (ValType.isNull())
+          continue;
         if (ValType->isAnyPointerType() || ValType->isReferenceType())
           ValType = ValType->getPointeeType();
         if (const FunctionProtoType *FPT = ValType->getAs<FunctionProtoType>())
diff --git a/test/SemaCXX/typo-correction-cxx17.cpp b/test/SemaCXX/typo-correction-cxx17.cpp
new file mode 100644 (file)
index 0000000..f137499
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
+
+namespace decomp_decl {
+void f() {
+       auto [this_is_a_typo] = this_is_a_typp(); // expected-error{{use of undeclared identifier 'this_is_a_typp'}}
+}
+}