Skip to content

[temp.res.general] It seems wrong to restrict IFNDR when no valid specialization can be generated to when "the innermost enclosing template is not instantiated" #973

Description

@HolyBlackCat

Full name of submitter (unless configured in github; will be published with the issue): Egor Mikhailov

Reference (section label): [temp.res.general]/6.1

Link to reflector thread (if any): none

Issue description:

[temp.res.general]/6.1

The program is ill-formed, no diagnostic required, if

(6.1) no valid specialization, ignoring static_assert-declarations that fail ([dcl.pre]), can be generated for a templated entity or a substatement of a constexpr if statement ([stmt.if]) within a templated entity and the innermost enclosing template is not instantiated, or

The intent of "and the innermost enclosing template is not instantiated" seems to be to remove the IFNDR status if an invalid specialization is actually produced, which in turn makes the program just IF. But the way it's currently worded is problematic.

Example 1:

template <typename T>
struct Foo
{
    Foo() {}
    Foo(T)
    {
        this->bar(); // IFNDR here?
    }
};

Foo<int> f;

Both GCC and Clang treat this->bar(); as IFNDR, which matches the intent. But since I have Foo<int> x;, which causes an instantiation of the innermost enclosing template (which is Foo), under the current wording the program turns from IFNDR to well-formed, which I guess isn't the intent.

Similarly, example 2:

template <typename T>
void a()
{
    if constexpr (sizeof(T) == 42)
    {
        int *a = 1; // IFNDR here?
    }
}

int main()
{
    a<int>();
}

I'm sure the intent is for this to be IFNDR, but since I have an instantiation of a<int>(), this is now well-formed.

Suggested resolution:

-and the innermost enclosing template is not instantiated
+and that templated entity or substatement respectively is not instantiated

Or split the sentence to something like

+no valid specialization, ignoring static_assert-declarations that fail ([dcl.pre]), can be generated for a templated entity and that entity is not instantiated, or for a substatement of a constexpr if statement ([stmt.if]) within a templated entity and that substatement is not instantiated, or

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions