Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
uselessgoddess opened this issue May 9, 2021 · 1 comment
Closed

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

uselessgoddess opened this issue May 9, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@uselessgoddess
Copy link

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?

@andreasfertig
Copy link
Owner

Hello @uselessgoddess,

thanks for reporting this issue :-) It made me (re-)discover ConstantExpr and its value. A fix is on its way.

Andreas

@andreasfertig andreasfertig added the bug Something isn't working label May 10, 2021
andreasfertig added a commit that referenced this issue May 10, 2021
Fixed #400: Show value of a `ConstantExpr` instead of the subexpr in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants