Created attachment 51004 [details] Source code to generate bug and GCC version info g++ treats a class with a constexpr cast function inconsistently when passed and captured by a lambda, with one usage producing the error message "error: use of ‘this’ in a constant expression". The error occurs in g++ 9.4.0 with -std=c++14 but not with -std=c++17. Apparently this problem does not occur with Godbolt, but I cannot test this myself.
Looks to be fixed in GCC 11+
Fixed with r11-88-g733195e367d84914.