News for hackers. Stuff that matters.
Re:Non-constant constant-expressions in C++ by Someone on Sunday April 26, 2015 @06:30PM (#9443556)
Easier (and bending the rules a bit):

  #include <iostream>
  
  constexpr int f(int line)
  {
      return line;
  }
  
  #define f() f(__LINE__)
  
  int main(int argc, const char * argv[]) {
      constexpr int x = f();
      constexpr int y = f();
      
      std::cout << "x = " << x << "; y = " << y;
      return EXIT_SUCCESS;
  }
Also, I don't think the language designers required

"This lack of dependency must inherently mean that it will yield the same value upon each invocation having the same set of arguments"

to be true. http://en.cppreference.com/w/cpp/language/constexpr only states:

"The constexpr specifier declares that it is possible to evaluate the value of the function or variable at compile time."

The draft of the C++ standard on my system states that as follows:

"Certain contexts require expressions that satisfy additional requirements as detailed in this sub-clause. Such expressions are called constant expressions. [ Note: Those expressions can be evaluated during translation. — end note ]"

Re:Non-constant constant-expressions in C++ by refp on Sunday April 26, 2015 @07:16PM (#9443672)
> "This lack of dependency must inherently mean that it will yield the same value upon each invocation having the same set of arguments"

That quote was written in a "this is what most of us used to think" sort of way, it was never intended to be read literally - though maybe I should clearify the intent.

I certainly agree with your post, and your little hack is very cute; +1! :-)