Skip to content

Revert "[Clang] skip default argument instantiation for non-defining friend declarations without specialization info to meet [dcl.fct.default] p4" #115404

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
Nov 8, 2024

Conversation

mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Nov 8, 2024

Reverts #113777

Reverted due to regression reported here: #113777 (comment)

@mizvekov mizvekov self-assigned this Nov 8, 2024
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 8, 2024

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

Reverts llvm/llvm-project#113777

Reverted due to regression reported here: #113777 (comment)


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

3 Files Affected:

  • (modified) clang/docs/ReleaseNotes.rst (-2)
  • (modified) clang/lib/Sema/SemaExpr.cpp (-11)
  • (modified) clang/test/CXX/temp/temp.res/p4.cpp (-19)
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0b0f2053f634ee..30bcb6313b6ade 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -636,8 +636,6 @@ Bug Fixes to C++ Support
   an implicitly instantiated class template specialization. (#GH51051)
 - Fixed an assertion failure caused by invalid enum forward declarations. (#GH112208)
 - Name independent data members were not correctly initialized from default member initializers. (#GH114069)
-- Fixed an assertion failure caused by invalid default argument substitutions in non-defining
-  friend declarations. (#GH113324).
 
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 68527d9da8c799..01d43317e33aed 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -6018,17 +6018,6 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl,
     } else {
       assert(Param && "can't use default arguments without a known callee");
 
-      // FIXME: We don't track member specialization info for non-defining
-      // friend declarations, so we will not be able to later find the function
-      // pattern. As a workaround, don't instantiate the default argument in
-      // this case. This is correct per wording and only an error recovery
-      // issue, as per [dcl.fct.default]p4:
-      //   if a friend declaration D specifies a default argument expression,
-      //   that declaration shall be a definition.
-      if (FDecl->getFriendObjectKind() != Decl::FOK_None &&
-          FDecl->getMemberSpecializationInfo() == nullptr)
-        return true;
-
       ExprResult ArgExpr = BuildCXXDefaultArgExpr(CallLoc, FDecl, Param);
       if (ArgExpr.isInvalid())
         return true;
diff --git a/clang/test/CXX/temp/temp.res/p4.cpp b/clang/test/CXX/temp/temp.res/p4.cpp
index 743ffed14d81a8..f54d8649f5da88 100644
--- a/clang/test/CXX/temp/temp.res/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/p4.cpp
@@ -185,22 +185,3 @@ template<typename T> struct S {
   friend void X::f(T::type);
 };
 }
-
-namespace GH113324 {
-template <typename = int> struct ct {
-  friend void f1(ct, int = 0);               // expected-error {{friend declaration specifying a default argument must be a definition}}
-  friend void f2(ct a, ct = decltype(a){ }); // expected-error {{friend declaration specifying a default argument must be a definition}}
-};
-
-template<class T> using alias = int;
-template<typename T> struct C {
-  // FIXME: We miss diagnosing the default argument instantiation failure (forming reference to void)
-  friend void f3(C, int a = alias<T&>(1)); // expected-error {{friend declaration specifying a default argument must be a definition}}
-};
-
-void test() {
-  f1(ct<>{});
-  f2(ct<>{});
-  f3(C<void>());
-}
-} // namespace GH113324

@mizvekov mizvekov merged commit 74deb66 into main Nov 8, 2024
9 of 11 checks passed
@mizvekov mizvekov deleted the revert-113777-fix/113324 branch November 8, 2024 00:53
Groverkss pushed a commit to iree-org/llvm-project that referenced this pull request Nov 15, 2024
…friend declarations without specialization info to meet [dcl.fct.default] p4" (llvm#115404)

Reverts llvm#113777

Reverted due to regression reported here:
llvm#113777 (comment)
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.

2 participants