https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118516
Bug ID: 118516 Summary: Misleading error message "call to non-'constexpr' function" when loop variable is not declared Product: gcc Version: 12.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: arvo at me dot com Target Milestone: --- Created attachment 60174 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60174&action=edit Minimal working example and compiler outputs Observed on Ubuntu 22.04 with GCC 12 (Ubuntu 12.3.0-1ubuntu1~22.04). Command line to reproduce: g++-12 --std=c++20 -c undeclared-loop-var.cxx The main element of the source code is a loop in which the loop variable is misspelled in the condition, and a call to a function is also made in the condition. Expected behavior: (only) error message "'i' was not declared in this scope", according to the misspelled loop variable Actual behavior: The expected error message does appear, but only after 9 (!) instances of the misleading error message "call to non-‘constexpr’ function ‘int foo()’", referring to the same line. It is unclear why 'foo()' being non-'constexpr' should be relevant here. Nothing at the use site seems to suggest that only 'constexpr' calls are allowed here. See the attachment for minimal source code and compiler outputs. Additional notes: - A coworker was able to reproduce this with a variety of GCC versions using godbolt.org. - Importantly, the behavior is observed with the --std=c++20 (or --std=c++23) command line option but is not observed if the option is omitted. In the latter case, the actual behavior matches the expected behavior.