llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Type Traits with an empty parameter pack crashes. Also skip arity checks

Open erichkeane opened this issue 5 years ago • 8 comments

Bugzilla Link 50494
Version trunk
OS All
CC @DougGregor,@futog,@zygoloid

Extended Description

See this for example: https://godbolt.org/z/G8onvPEqM

template<typename ...Ts>
bool foo() {
 return __is_pointer(Ts...);
}

void instant() {
    foo<int>(); // #1
    foo<int, int*>(); // #2
    foo<>(); // #3
}

#1 works correctly.

#2 should probably emit a diagnostic, since now there are two parameters to a Unary type trait.

#3 should probably ALSO emit a diagnostic, since there are NO parameters to a unary type trait.

erichkeane avatar May 26 '21 17:05 erichkeane

Hi, I'm taking a look. Regards, Gergely

futog avatar Jun 09 '21 04:06 futog

Given the very limited intended scope of these builtins, I think it's fine to do whatever's simplest -- neither supporting nor rejecting a pack expansion in this context seems like it should be an explicit goal. If we already make an explicit attempt to make pack expansions work here, it might be easier to add the missing arity check than to remove the support (especially if it means we can share code between N-ary type traits and unary ones). But if we do choose to keep the support, I'd expect things like this to work:

template<typename ...T>
struct A {
    template<typename ...U>
    static bool b = __is_trivially_copyable(T..., U...);
};

... which we currently reject due to the early arity check.

Can we simply reject pack expansions in the argument of all unary type traits? The traits are only intended for use when implementing the corresponding standard library facilities, and we don't need to support pack expansion for that.

If YOU are ok with it, I am :) I just ran across it while developing a different feature and figured we should capture it.

If that is our approach, this is likely a somewhat easy 'fix', almost beginner level (for anyone watching:) ), since it just requires removing a little code during TreeTransform and during Parsing.

erichkeane avatar May 26 '21 18:05 erichkeane

Can we simply reject pack expansions in the argument of all unary type traits? The traits are only intended for use when implementing the corresponding standard library facilities, and we don't need to support pack expansion for that.

assigned to @futog

erichkeane avatar May 26 '21 17:05 erichkeane

@llvm/issue-subscribers-clang-frontend

Author: Erich Keane (erichkeane)

| | | | --- | --- | | Bugzilla Link | [50494](https://llvm.org/bz50494) | | Version | trunk | | OS | All | | CC | @DougGregor,@futog,@zygoloid |

Extended Description

See this for example: https://godbolt.org/z/G8onvPEqM

template&lt;typename ...Ts&gt;
bool foo() {
 return __is_pointer(Ts...);
}

void instant() {
    foo&lt;int&gt;(); // #<!-- -->1
    foo&lt;int, int*&gt;(); // #<!-- -->2
    foo&lt;&gt;(); // #<!-- -->3
}

#<!-- -->1 works correctly.

#<!-- -->2 should probably emit a diagnostic, since now there are two parameters to a Unary type trait.

#<!-- -->3 should probably ALSO emit a diagnostic, since there are NO parameters to a unary type trait.

llvmbot avatar Apr 26 '25 08:04 llvmbot

@llvm/issue-subscribers-c-11

Author: Erich Keane (erichkeane)

| | | | --- | --- | | Bugzilla Link | [50494](https://llvm.org/bz50494) | | Version | trunk | | OS | All | | CC | @DougGregor,@futog,@zygoloid |

Extended Description

See this for example: https://godbolt.org/z/G8onvPEqM

template&lt;typename ...Ts&gt;
bool foo() {
 return __is_pointer(Ts...);
}

void instant() {
    foo&lt;int&gt;(); // #<!-- -->1
    foo&lt;int, int*&gt;(); // #<!-- -->2
    foo&lt;&gt;(); // #<!-- -->3
}

#<!-- -->1 works correctly.

#<!-- -->2 should probably emit a diagnostic, since now there are two parameters to a Unary type trait.

#<!-- -->3 should probably ALSO emit a diagnostic, since there are NO parameters to a unary type trait.

llvmbot avatar Apr 26 '25 08:04 llvmbot

Appears to be fixed in Clang 16: https://godbolt.org/z/o9anj56K3

Endilll avatar Apr 26 '25 08:04 Endilll