adamcz created this revision. Herald added a subscriber: kristof.beyls. adamcz requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
There already was a check for undeduced and incomplete types, but it failed to trigger when outer type (SubstTemplateTypeParm in test) looked fine, but inner type was not. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D100667 Files: clang/lib/Sema/SemaChecking.cpp clang/test/SemaCXX/cxx17-undeduced-alignment.cpp Index: clang/test/SemaCXX/cxx17-undeduced-alignment.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/cxx17-undeduced-alignment.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -std=c++17 -verify %s +// +// Verifies that clang no longer crashes on undeduced, sugared types. + +template <class T> void foo(T &t); +template <typename T> +void bar(T t) { + foo(t); +} + +template <typename T = void *> +struct S { // expected-note {{candidate}} + S(T t); // expected-note {{candidate}} + ~S(); +}; +template <typename T> S(T t) -> S<void *>; + +void baz() { + // S(123) is undeduced, but when passed to foo() via bar() it is wrapped in + // SubstTemplateTypeParm, for which isUndeduced() is false. + bar(S(123)); // expected-error {{no matching conversion}} +} Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -4540,8 +4540,15 @@ // Find expected alignment, and the actual alignment of the passed object. // getTypeAlignInChars requires complete types - if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() || - ParamTy->isUndeducedType() || ArgTy->isUndeducedType()) + auto CheckTypeOK = [](QualType Ty) { + if (Ty->isIncompleteType() || Ty->isUndeducedType()) + return false; + if (auto *DesugaredTy = Ty->getUnqualifiedDesugaredType()) + if (DesugaredTy->isIncompleteType() || DesugaredTy->isUndeducedType()) + return false; + return true; + }; + if (!CheckTypeOK(ParamTy) || !CheckTypeOK(ArgTy)) return; CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);
Index: clang/test/SemaCXX/cxx17-undeduced-alignment.cpp =================================================================== --- /dev/null +++ clang/test/SemaCXX/cxx17-undeduced-alignment.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -std=c++17 -verify %s +// +// Verifies that clang no longer crashes on undeduced, sugared types. + +template <class T> void foo(T &t); +template <typename T> +void bar(T t) { + foo(t); +} + +template <typename T = void *> +struct S { // expected-note {{candidate}} + S(T t); // expected-note {{candidate}} + ~S(); +}; +template <typename T> S(T t) -> S<void *>; + +void baz() { + // S(123) is undeduced, but when passed to foo() via bar() it is wrapped in + // SubstTemplateTypeParm, for which isUndeduced() is false. + bar(S(123)); // expected-error {{no matching conversion}} +} Index: clang/lib/Sema/SemaChecking.cpp =================================================================== --- clang/lib/Sema/SemaChecking.cpp +++ clang/lib/Sema/SemaChecking.cpp @@ -4540,8 +4540,15 @@ // Find expected alignment, and the actual alignment of the passed object. // getTypeAlignInChars requires complete types - if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() || - ParamTy->isUndeducedType() || ArgTy->isUndeducedType()) + auto CheckTypeOK = [](QualType Ty) { + if (Ty->isIncompleteType() || Ty->isUndeducedType()) + return false; + if (auto *DesugaredTy = Ty->getUnqualifiedDesugaredType()) + if (DesugaredTy->isIncompleteType() || DesugaredTy->isUndeducedType()) + return false; + return true; + }; + if (!CheckTypeOK(ParamTy) || !CheckTypeOK(ArgTy)) return; CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits