From 6e6aa44c7d14b37a12e40c6b36478045d6004a0a Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Wed, 31 Jan 2024 06:58:58 -0800 Subject: [PATCH] =?UTF-8?q?Revert=20"[Clang][Sema]=20fix=20outline=20membe?= =?UTF-8?q?r=20function=20template=20with=20defau=E2=80=A6=20(#80144)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …lt align crash (#78400)" This reverts commit 7b3389980ddbd84f72ccc4776889c67519cc2c14. A regression was discovered here: https://github.com/llvm/llvm-project/pull/78400 and the author requested a revert to give time to review. --- clang/docs/ReleaseNotes.rst | 4 -- clang/lib/Sema/SemaTemplateInstantiate.cpp | 13 +---- clang/test/SemaTemplate/default-parm-init.cpp | 50 ------------------- 3 files changed, 2 insertions(+), 65 deletions(-) delete mode 100644 clang/test/SemaTemplate/default-parm-init.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 37f2423441a30c..2fa2bab867d033 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -164,10 +164,6 @@ Bug Fixes to C++ Support - Fix crash when using lifetimebound attribute in function with trailing return. Fixes (`#73619 `_) -- Fix a crash when specializing an out-of-line member function with a default - parameter where we did an incorrect specialization of the initialization of - the default parameter. - Fixes (`#68490 `_) - Addressed an issue where constraints involving injected class types are perceived distinct from its specialization types. (`#56482 `_) diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index 41e58b91de4e08..e12186d7d82f8d 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -3049,7 +3049,6 @@ bool Sema::SubstDefaultArgument( // default argument expression appears. ContextRAII SavedContext(*this, FD); std::unique_ptr LIS; - MultiLevelTemplateArgumentList NewTemplateArgs = TemplateArgs; if (ForCallExpr) { // When instantiating a default argument due to use in a call expression, @@ -3062,19 +3061,11 @@ bool Sema::SubstDefaultArgument( /*ForDefinition*/ false); if (addInstantiatedParametersToScope(FD, PatternFD, *LIS, TemplateArgs)) return true; - if (FD->isOutOfLine()) { - TemplateArgumentList *CurrentTemplateArgumentList = - TemplateArgumentList::CreateCopy(getASTContext(), - TemplateArgs.getInnermost()); - NewTemplateArgs = getTemplateInstantiationArgs( - FD, FD->getDeclContext(), /*Final=*/false, - CurrentTemplateArgumentList, /*RelativeToPrimary=*/true); - } } runWithSufficientStackSpace(Loc, [&] { - Result = SubstInitializer(PatternExpr, NewTemplateArgs, - /*DirectInit*/ false); + Result = SubstInitializer(PatternExpr, TemplateArgs, + /*DirectInit*/false); }); } if (Result.isInvalid()) diff --git a/clang/test/SemaTemplate/default-parm-init.cpp b/clang/test/SemaTemplate/default-parm-init.cpp deleted file mode 100644 index 4bcea7eaa10176..00000000000000 --- a/clang/test/SemaTemplate/default-parm-init.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++17 -verify %s -// RUN: %clang_cc1 -fsyntax-only -std=c++20 -verify %s -// expected-no-diagnostics - -template -struct Problem{ - template - constexpr int FuncAlign(int param = alignof(FunctionTemplateParam)); - - template - constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam)); - - template - constexpr int FuncAlign2(int param = alignof(TemplateParam)); - - template - constexpr int FuncSizeof2(int param = sizeof(TemplateParam)); -}; - -template <> -template -constexpr int Problem::FuncAlign(int param) { - return param; -} - -template <> -template -constexpr int Problem::FuncSizeof(int param) { - return param; -} - -template <> -template -constexpr int Problem::FuncAlign2(int param) { - return param; -} - -template <> -template -constexpr int Problem::FuncSizeof2(int param) { - return param; -} - -int main(){ - Problem p = {}; - static_assert(p.FuncAlign() == alignof(char)); - static_assert(p.FuncSizeof() == sizeof(char)); - static_assert(p.FuncAlign2() == alignof(int)); - static_assert(p.FuncSizeof2() == sizeof(int)); -}