Skip to content

[clang] Bogus error about converting pointer to void* when using void* constant parameter/NTTP and a generic lambda #145012

Open
@MitalAshok

Description

@MitalAshok

Compiled with -std=c++20 -fsyntax-only https://godbolt.org/z/16vaW6c6M:

extern int x;

template<void* p>
void f() {
    []<typename = void>() {
        static_assert(p == &x);
    }();
}

int main() {
    f<(void*)&x>();
}
<source>:6:23: error: conversion from 'int *' to 'void *' is not allowed in a converted constant expression
    6 |         static_assert(p == &x);
      |                       ^
<source>:5:5: note: in instantiation of function template specialization 'f()::(anonymous class)::operator()<void>' requested here
    5 |     []<typename = void>() {
      |     ^
<source>:11:5: note: in instantiation of function template specialization 'f<&x>' requested here
   11 |     f<(void*)&x>();
      |     ^
<source>:3:16: note: template parameter is declared here
    3 | template<void* p>
      |                ^

Removing the <typename = void> (i.e., making it a non-generic lambda) makes this compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"rejects-valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions