PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, June 25, 2022

[FIXED] Why does `consteval` not behave as expected?

 June 25, 2022     c++, c++20, compiler-errors, consteval, constexpr     No comments   

Issue

inline consteval unsigned char operator""_UC(const unsigned long long n)
{
    return static_cast<unsigned char>(n);
}

inline consteval char f1(auto const octet)
{
    return char(octet >> 4_UC);
}

inline constexpr char f2(auto const octet)
{
    return char(octet >> 4_UC);
}

int main()
{
    auto c1 = f1('A'); // ok
    auto c2 = f2('A'); // error

    return c1 + c2;
}

Compiled with: clang++-14 -std=c++20 -stdlib=libc++, and the error message is:

undefined reference to `operator"" _UC(unsigned long long)'

See online demo

Why does f1() is ok while f2() is not?

Why does consteval not behave as expected?


Solution

This is a bug of clang 14 and has been fixed.

See: https://github.com/llvm/llvm-project/commit/ca844ab01c3f9410ceca967c09f809400950beae



Answered By - xmllmx
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing