[clang] [clang] Fix overload resolution ranking of inherited constructors (PR #132830)
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 28 15:57:37 PDT 2025
================
@@ -169,6 +169,20 @@ B b;
// since-cxx11-error at -1 {{call to implicitly-deleted default constructor of 'B'}}
// since-cxx11-note@#cwg2273-B {{default constructor of 'B' is implicitly deleted because base class 'A' has a deleted default constructor}}
// since-cxx11-note@#cwg2273-A {{'A' has been explicitly marked deleted here}}
+
+struct X {
+ X(float); // since-cxx11-note {{candidate inherited constructor}}
+ X(void*, int = 0) = delete;
+};
+
+struct Y : X {
+ using X::X; // since-cxx11-note {{constructor from base class 'X' inherited here}}
+ Y(double); // since-cxx11-note {{candidate constructor}}
+ Y(void* const, long = 1);
+};
+
+Y y = 1; // since-cxx11-error {{conversion from 'int' to 'Y' is ambiguous}}
+Y z = nullptr;
----------------
Endilll wrote:
> Since the const here is at the top level, it is ignored when forming the function type.
Formally speaking, what matters here is that adjusted parameters types form parameter-type-list, which overload resolution seems to be concerned with (https://eel.is/c++draft/over#match.general-1, even if I don't really trust this wording). But you are correct.
Then, if `hasSameUnqualifiedType` aspect of you implementation is supposed to take care of that, I think you need to reconsider, because stripping top-level cv-qualifiers in not the only adjustment that happens (https://eel.is/c++draft/dcl.fct#4). I'd like to see additional tests with parameters of array and function types.
Also, I think it would be worth leaving a comment that default arguments do not contribute to the set of arguments that [over.match.best] considers. (Instead, parameters which have default arguments are discarded per https://eel.is/c++draft/over#match.viable-2.3.sentence-2)
https://github.com/llvm/llvm-project/pull/132830
More information about the cfe-commits
mailing list