Skip to content

Clang's algorithm for choosing overloads that don't need to instantiate a class template might have room for improvement #61821

Open
@cjdb

Description

@cjdb

GCC test (concepts-conv3.C) currently fails. I think Clang is in the clear for it failing per [temp.inst]/9, but I wonder if we ought to mimic GCC here, since it will improve template ergonomics.

// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s

// Here, normal overload resolution would consider B::operator bool when
// evaluating A(b), leading to a hard error instantiating Error<int>, but we
// avoid considering it by noticing that converting bool (a scalar) to A (a
// class) would require a user-defined conversion, which is not allowed when
// we're already dealing with the user-defined conversion to A.

// This seems to be allowed by [temp.inst]/9: "If the function selected by
// overload resolution (12.4) can be determined without instantiating a class
// template definition, it is unspecified whether that instantiation actually
// takes place."

template <class T>
struct Error { static constexpr auto value = T::value; };

struct A { A(const A&); };

template <class T>
struct B { operator bool() requires Error<T>::value; };

template <class T>
concept C = requires (B<T> b) { A(b); };

static_assert(!C<int>);

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clang:frontendLanguage frontend issues, e.g. anything involving "Sema"conceptsC++20 conceptsquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions