Bug 101054 - Compiler inconsistently gives error when constexpr class function is called from lambda
Summary: Compiler inconsistently gives error when constexpr class function is called f...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 9.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: c++-lambda
Depends on:
Blocks: lambdas
  Show dependency treegraph
 
Reported: 2021-06-14 05:25 UTC by Peter Fletcher
Modified: 2024-03-27 07:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 11.1.0
Known to fail: 10.3.0
Last reconfirmed: 2022-03-28 00:00:00


Attachments
Source code to generate bug and GCC version info (1.63 KB, text/plain)
2021-06-14 05:25 UTC, Peter Fletcher
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Fletcher 2021-06-14 05:25:50 UTC
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.
Comment 1 Andrew Pinski 2021-08-12 23:36:03 UTC
Looks to be fixed in GCC 11+
Comment 2 Martin Liška 2022-03-28 11:08:02 UTC
Fixed with r11-88-g733195e367d84914.