Skip to content

Revert "[Clang][Sema] fix outline member function template with defau… #80144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

erichkeane
Copy link
Collaborator

…lt align crash (#78400)"

This reverts commit 7b33899.

A regression was discovered here:
#78400

and the author requested a revert to give time to review.

…lt align crash (llvm#78400)"

This reverts commit 7b33899.

A regression was discovered here:
llvm#78400

and the author requested a revert to give time to review.
@erichkeane erichkeane requested review from jcsxky and bgra8 January 31, 2024 14:27
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 31, 2024
@erichkeane
Copy link
Collaborator Author

Sitting here for CI, will merge when it passes.

@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2024

@llvm/pr-subscribers-clang

Author: Erich Keane (erichkeane)

Changes

…lt align crash (#78400)"

This reverts commit 7b33899.

A regression was discovered here:
#78400

and the author requested a revert to give time to review.


Full diff: https://github.com/llvm/llvm-project/pull/80144.diff

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (-4)
  • (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+2-11)
  • (removed) clang/test/SemaTemplate/default-parm-init.cpp (-50)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 37f2423441a30..2fa2bab867d03 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 <https://github.com/llvm/llvm-project/issues/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 <https://github.com/llvm/llvm-project/issues/68490>`_)
 - Addressed an issue where constraints involving injected class types are perceived
   distinct from its specialization types.
   (`#56482 <https://github.com/llvm/llvm-project/issues/56482>`_)
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 41e58b91de4e0..e12186d7d82f8 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<LocalInstantiationScope> 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 4bcea7eaa1017..0000000000000
--- 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<typename TemplateParam>
-struct Problem{
-  template<typename FunctionTemplateParam>
-  constexpr int FuncAlign(int param = alignof(FunctionTemplateParam));
-
-  template<typename FunctionTemplateParam>
-  constexpr int FuncSizeof(int param = sizeof(FunctionTemplateParam));
-
-  template<typename FunctionTemplateParam>
-  constexpr int FuncAlign2(int param = alignof(TemplateParam));
-
-  template<typename FunctionTemplateParam>
-  constexpr int FuncSizeof2(int param = sizeof(TemplateParam));
-};
-
-template <>
-template<typename FunctionTemplateParam>
-constexpr int Problem<int>::FuncAlign(int param) {
-	return param;
-}
-
-template <>
-template<typename FunctionTemplateParam>
-constexpr int Problem<int>::FuncSizeof(int param) {
-	return param;
-}
-
-template <>
-template<typename FunctionTemplateParam>
-constexpr int Problem<int>::FuncAlign2(int param) {
-	return param;
-}
-
-template <>
-template<typename FunctionTemplateParam>
-constexpr int Problem<int>::FuncSizeof2(int param) {
-	return param;
-}
-
-int main(){
-    Problem<int> p = {};
-    static_assert(p.FuncAlign<char>() == alignof(char));
-    static_assert(p.FuncSizeof<char>() == sizeof(char));
-    static_assert(p.FuncAlign2<char>() == alignof(int));
-    static_assert(p.FuncSizeof2<char>() == sizeof(int));
-}

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff e538486e90539096e7851d0deba4ea9ed94fced2 be2437105566a677fa6adcc676beb19ddfb2d106 -- clang/lib/Sema/SemaTemplateInstantiate.cpp
View the diff from clang-format here.
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index e12186d7d8..2c053f6781 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3065,7 +3065,7 @@ bool Sema::SubstDefaultArgument(
 
     runWithSufficientStackSpace(Loc, [&] {
       Result = SubstInitializer(PatternExpr, TemplateArgs,
-                                /*DirectInit*/false);
+                                /*DirectInit*/ false);
     });
   }
   if (Result.isInvalid())

@jcsxky
Copy link
Contributor

jcsxky commented Jan 31, 2024

Thank for your help!

@erichkeane erichkeane merged commit 6e6aa44 into llvm:main Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants