Skip to content
Snippets Groups Projects
user avatar
Simon Martin authored
We segfault upon the following invalid code

=== cut here ===
template <int> struct S {
  friend void foo (int a = []{}());
};
void foo (int a) {}
int main () {
  S<0> t;
  foo ();
}
=== cut here ===

The problem is that we end up with a LAMBDA_EXPR callee in
set_flags_from_callee, and dereference its NULL_TREE
TREE_TYPE (TREE_TYPE (..)).

This patch sets the default argument to error_mark_node and gives a hard
error for template class friend functions that do not meet the
requirement in C++17 11.3.6/4 (the change is restricted to templates per
discussion with Jason).

	PR c++/118319

gcc/cp/ChangeLog:

	* decl.cc (grokfndecl): Inspect all friend function parameters.
	If it's not valid for them to have a default value and we're
	processing a template, set the default value to error_mark_node
	and give a hard error.

gcc/testsuite/ChangeLog:

	* g++.dg/parse/defarg18.C: New test.
	* g++.dg/parse/defarg18a.C: New test.
198f4df0
History
Name Last commit Last update