Skip to content

Reference to parameter of one function, spliced into body of another without error #292

@rbock

Description

@rbock

Hi,

While playing with the new splice syntax (beautiful, btw), I ran into this curiosity:

using info = decltype(reflexpr(void));

template<info V> 
constexpr auto get()
{
  return [<V>];
}

template<typename T>
constexpr auto copy_indirect(T&& t)
{
  // IFF we are trying to obtain a constexpr value from this function, this fails:
  return get<reflexpr(t)>();
  // "function parameter 't' with unknown value cannot be used in a constant expression"
}

template<typename T>
constexpr auto copy_semi_direct(T&& t)
{
  constexpr auto i = reflexpr(t); // No problem here
  return [<i>];
} 

template<typename T>
constexpr auto copy_direct(T&& t)
{
  return [<reflexpr(t)>]; // No problem here
}

int main(int argc, char**argv)
{
  auto a = copy_indirect(1); // Works
  auto b = copy_indirect(argc); // Works
  constexpr auto x = copy_indirect(1); // Fails
  constexpr auto y = copy_semi_direct(1); // Works
  constexpr auto z = copy_direct(1); // Works
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions