Home > Net >  C call to list constructor is ambiguous
C call to list constructor is ambiguous

Time:02-11

I'm trying to build an old C project on a modern version of Clang and getting lots of ambiguous errors. I don't have much C experience so apologies if this is basic stuff.

/home/ubuntu/NameAndTypeResolver.cpp:124:40: error: call to constructor of 'list<list<const dev::libcrunch::ContractDefinition *> >' is ambiguous
        list<list<ContractDefinition const*>> input(1, {});
                                              ^     ~~~~~

I'm not sure what the compilers asking for here. Additionally what is the {} syntax?

CodePudding user response:

To solve your problem do this:

std::list<std::list<ContractDefinition const*>> input(1);
                                           //          ^^^^ drop the ,{}

The {} is an attempt to constructor an object of type std::list<ContractDefinition const*> (i.e. a single member of the input).

In C 11 the original line would have been valid as it was unambiguously making a single object of std::list<ContractDefinition const*> using the default constructor.

But in C 17 (and later, not sure if it applies to C 14) the {} can be used for the default constructor and to create an initializer list (std::initializer_list).

The std::list<X> has a constructor that takes (<Count>, <Object>). When the compiler sees '{}it can default construct anXusingX{}or create anstd::initializer_list` (or length zero) both are valid options in this context. The compiler is not allowed to make that kind of determination which to use (even though they both result in the same thing in this case).

I hope I got that correct.
I'll check for negative marks in the morning :-)

  • Related