Skip to content

Reland [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 #115487

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 20 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5e24d21
[Clang] skip default argument instantiation for non-defining friend d…
a-tarasyuk Nov 8, 2024
3ad3b6c
update comments
a-tarasyuk Nov 8, 2024
ed851fa
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/…
a-tarasyuk Nov 8, 2024
a181584
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/…
a-tarasyuk Nov 8, 2024
971fcc3
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Nov 12, 2024
3fffde4
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Nov 19, 2024
09215de
move cases that cause code generation failures to the appropriate folder
a-tarasyuk Nov 21, 2024
41d53cb
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/…
a-tarasyuk Nov 21, 2024
dbb2c1d
remove unnecessary tests
a-tarasyuk Nov 25, 2024
1b03fc8
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Nov 25, 2024
a0dbd9e
revert required tests
a-tarasyuk Nov 25, 2024
d2928d9
Merge branch 'fix/113324-follow_up' of https://github.com/a-tarasyuk/…
a-tarasyuk Nov 25, 2024
9f0c3ed
update comments
a-tarasyuk Nov 26, 2024
bc82521
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Nov 27, 2024
1b375a2
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Dec 1, 2024
8848f53
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Dec 6, 2024
e52e9f4
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Dec 8, 2024
192c21d
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Dec 16, 2024
ab7da5d
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Dec 17, 2024
3921f21
Merge branch 'main' into fix/113324-follow_up
a-tarasyuk Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,8 @@ Bug Fixes to C++ Support
missing placeholder return type. (#GH78694)
- Fixed a bug where bounds of partially expanded pack indexing expressions were checked too early. (#GH116105)
- Fixed an assertion failure caused by using ``consteval`` in condition in consumed analyses. (#GH117385)
- Fixed an assertion failure caused by invalid default argument substitutions in non-defining
friend declarations. (#GH113324)
- Fix a crash caused by incorrect argument position in merging deduced template arguments. (#GH113659)
- Fixed a parser crash when using pack indexing as a nested name specifier. (#GH119072)
- Fixed a null pointer dereference issue when heuristically computing ``sizeof...(pack)`` expressions. (#GH81436)
Expand Down
11 changes: 11 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4703,6 +4703,17 @@ bool Sema::InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD,
ParmVarDecl *Param) {
assert(Param->hasUninstantiatedDefaultArg());

// 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 the standard and only an issue for recovery
// purposes. [dcl.fct.default]p4:
// if a friend declaration D specifies a default argument expression,
// that declaration shall be a definition.
if (FD->getFriendObjectKind() != Decl::FOK_None &&
!FD->getTemplateInstantiationPattern())
return true;

// Instantiate the expression.
//
// FIXME: Pass in a correct Pattern argument, otherwise
Expand Down
20 changes: 20 additions & 0 deletions clang/test/CXX/temp/temp.res/p4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,23 @@ template<typename T> struct S {
friend void X::f(T::type);
};
}

namespace GH113324 {
template <typename = int> struct S1 {
friend void f1(S1, int = 0); // expected-error {{friend declaration specifying a default argument must be a definition}}
friend void f2(S1 a, S1 = decltype(a){}); // expected-error {{friend declaration specifying a default argument must be a definition}}
};

template <class T> using alias = int;
template <typename T> struct S2 {
// FIXME: We miss diagnosing the default argument instantiation failure
// (forming reference to void)
friend void f3(S2, int a = alias<T &>(1)); // expected-error {{friend declaration specifying a default argument must be a definition}}
};

void test() {
f1(S1<>{});
f2(S1<>{});
f3(S2<void>());
}
} // namespace GH113324
11 changes: 11 additions & 0 deletions clang/test/CodeGenCXX/default-arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ void g() {
}
}

namespace GH113324 {
struct S1 {
friend void f(S1, int = 42) {}
};

void test() {
S1 s1;
f(s1);
}
};

struct A1 {
A1();
~A1();
Expand Down
Loading