diff --git a/rules/S1709/cfamily/rule.adoc b/rules/S1709/cfamily/rule.adoc index d3e13b87168..e5b8968e521 100644 --- a/rules/S1709/cfamily/rule.adoc +++ b/rules/S1709/cfamily/rule.adoc @@ -61,6 +61,26 @@ int test(Bar& bar, Baz& baz) { === Exceptions +The issue is not raised for constructors that have a single parameter of type `std::initializer_list` - +such constructors have special meaning and allow objects to be constructed from brace delimited list of initializers. + +[source,cpp] +---- +struct Container { + Container(std::initializer_list elems); // Compliant +}; + +void handle(Container const& c); + +int test(Bar& bar, Baz& baz) { + Container c1{1, 2, 3}; // OK whether the constructor is explicit or not + Container c2 = {1, 2, 3}; // Ill-formed if constructor would be explicit + handle({1, 2, 3}); // Ill-formed if constructor would be explicit + handle(Container{1, 2, 3}); // OK whether the constructor is explicit or not +} +---- + + {cpp}20 introduced conditional `explicit(expr)` that allows developers to make a constructor or conversion operator conditionally explicit depending on the value of `expr`. The new syntax allows a constructor or conversion operator declared with an `explicit(expr)` specifier to be implicit when `expr` evaluates to `false`. The issue is not raised in such situation.