[Bug c++/89605] A method cannot have two identical lambdas as default arguments

2021-04-21 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89605

Marek Polacek  changed:

   What|Removed |Added

 Resolution|--- |DUPLICATE
 Status|NEW |RESOLVED

--- Comment #6 from Marek Polacek  ---
Dup I think.

*** This bug has been marked as a duplicate of bug 91241 ***

[Bug c++/89605] A method cannot have two identical lambdas as default arguments

2020-10-30 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89605

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org,
   ||jason at gcc dot gnu.org,
   ||mpolacek at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek  ---
Reduced testcase:

namespace std {
template  using a = struct _Any_data;
template  struct function;
template  class F;
template 
struct F {
  static b bar(const _Any_data &, c &&...) {}
};
template  struct function {
  template  using d = int;
  template , void>, typename = d>
  function(e);
  using h = b (*)(const _Any_data &, c &&...);
  h f;
};
template 
template 
function::function(e) { f = F::bar; }
}
class S {
  using G = std::function;
  void foo(const G & = [](double) {}, const G & = [](double) {});
};
void S::foo(const G &, const G &) { foo(); }

Seems the problem is that the method's parameter list is parsed multiple times,
once on the method declaration (line 22 above) and then again on the method
definition (line 24).
In LAMBDA_TYPE_EXTRA_SCOPE we record the PARM_DECLs of the declaration, but
DECL_ARGUMENTS will get the PARM_DECLs from the definition.

So, I think either we want during duplicate_decls adjust the PARM_DECLs in
LAMBDA_TYPE_EXTRA_SCOPE somehow from the old PARM_DECLs to the ones that won,
or store there for PARM_DECLs something different (instead of PARM_DECL say the
PARM_DECL or FUNCTION_DECL and the argument's number, or write_local_name needs
to use some other way to find map the PARM_DECLs into argument numbers (wonder
e.g. if it couldn't walk_tree the existing PARM_DECLs and corresponding
argument types including initializers for the entity, the same lambda shouldn't
appear in multiple of them).

[Bug c++/89605] A method cannot have two identical lambdas as default arguments

2019-03-06 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89605

Jonathan Wakely  changed:

   What|Removed |Added

   Keywords||ice-on-valid-code
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-03-06
 Ever confirmed|0   |1

--- Comment #4 from Jonathan Wakely  ---
Although with trunk it crashes the compiler:

l.cc: In member function 'void S::_foo(const ConverterFunction&, const
ConverterFunction&)':
l.cc:20:34: warning: unused parameter 'converterBack' [-Wunused-parameter]
   20 | const ConverterFunction& converterBack)
  | ~^
l.cc: At global scope:
l.cc:29:1: error: Two symbols with same comdat_group are not linked by the
same_comdat_group list.
   29 | }
  | ^
_ZNSt9_Any_data9_M_accessIZN1S4_fooERKSt8functionIFddEES6_Ed_UldE_EERT_v/919
(_Tp& std::_Any_data::_M_access() [with _Tp = S::])
@0x7f0881f599d8
  Type: function definition analyzed
  Visibility: no_reorder public weak comdat
comdat_group:_ZNSt9_Any_data9_M_accessIZN1S4_fooERKSt8functionIFddEES6_Ed_UldE_EERT_v
one_only visibility_specified
  previous sharing asm name: 915
  References: 
  Referring: 
  Function flags: body
  Called by: static void
std::_Function_base::_Base_manager<_Functor>::_M_destroy(std::_Any_data&,
std::true_type) [with _Functor = S::]/877 
  Calls: void* std::_Any_data::_M_access()/279 
_ZNSt9_Any_data9_M_accessIZN1S4_fooERKSt8functionIFddEES6_Ed_UldE_EERT_v/915
(_Tp& std::_Any_data::_M_access() [with _Tp = S::])
@0x7f0881f59438
  Type: function definition analyzed
  Visibility: no_reorder public weak comdat
comdat_group:_ZNSt9_Any_data9_M_accessIZN1S4_fooERKSt8functionIFddEES6_Ed_UldE_EERT_v
one_only visibility_specified
  next sharing asm name: 919
  References: 
  Referring: 
  Function flags: body
  Called by: static void
std::_Function_base::_Base_manager<_Functor>::_M_destroy(std::_Any_data&,
std::true_type) [with _Functor = S::]/872 
  Calls: void* std::_Any_data::_M_access()/279 
l.cc:29:1: internal compiler error: symtab_node::verify failed
0xb050c9 symtab_node::verify_symtab_nodes()
/home/jwakely/src/gcc/gcc/gcc/symtab.c:1260
0xb18564 symtab_node::checking_verify_symtab_nodes()
/home/jwakely/src/gcc/gcc/gcc/cgraph.h:637
0xb18564 symbol_table::compile()
/home/jwakely/src/gcc/gcc/gcc/cgraphunit.c:2602
0xb1a99c symbol_table::compile()
/home/jwakely/src/gcc/gcc/gcc/cgraphunit.c:2599
0xb1a99c symbol_table::finalize_compilation_unit()
/home/jwakely/src/gcc/gcc/gcc/cgraphunit.c:2865
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

[Bug c++/89605] A method cannot have two identical lambdas as default arguments

2019-03-06 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89605

--- Comment #3 from Jonathan Wakely  ---
The code *does* compile, but GCC outputs duplicate symbols, so it doesn't
assemble (or link).

[Bug c++/89605] A method cannot have two identical lambdas as default arguments

2019-03-06 Thread xavier at cremaschi dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89605

--- Comment #2 from xavier at cremaschi dot fr ---
rguenth are you sure for the 'link-failure' keyword ? 

It's truly a compilation error, triggered while compiling a given c++ file, it
does NOT wait until linking to fail.

[Bug c++/89605] A method cannot have two identical lambdas as default arguments

2019-03-06 Thread xavier at cremaschi dot fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89605

--- Comment #1 from xavier at cremaschi dot fr ---
FYI it also compiles if there is no class but just a free function :

#include 
#include 
#include 

using namespace std;

using ConverterFunction = function;

void _foo(
const ConverterFunction& converter = [](double value) -> double
{ return value; },
const ConverterFunction& converterBack = [](double value) ->
double { return value; }
);

void _foo(
const ConverterFunction& converter,
const ConverterFunction& converterBack)
{
cout << "foo " << converter(42) << endl;
}

int main() {
_foo();
return 0;
}