Skip to content

This is a bug. Or should it be? #400

@uselessgoddess

Description

@uselessgoddess

Here is my code

#include <concepts>

auto foo(auto x)
{
   if constexpr (std::same_as<int, decltype(x)>)
   {
      return 1;
   }
   return 2;
}

int main()
{
	foo(1);
        foo(1.0);
}

Here is the C++ Insights translation

#include <concepts>

auto foo(auto x)
{
   if constexpr (std::same_as<int, decltype(x)>)
   {
       return 1;
   }
   return 2;
}

#ifdef INSIGHTS_USE_TEMPLATE
template<>
int foo<int>(int x)
{
  if constexpr(std::same_as<int, int>) {
    return 1;
  } 
  
  return 2;
}
#endif


#ifdef INSIGHTS_USE_TEMPLATE
template<>
int foo<double>(double x)
{
  if constexpr(std::same_as<int, double>) {
  } 
  
  return 2;
}
#endif


int main()
{
  foo(1);
  foo(1.0);
}

Why

if constexpr(std::same_as<int, int>) {
    return 1;
} 

But

if constexpr(std::same_as<int, double>) {
} 

If C++ Insights doesn't expand constexpr expressions into their values, then why does the second option look so strange?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions