https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123303
Bug ID: 123303
Summary: Recursive function causes infinite loop in compilation
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: lluis.alemany.puig at gmail dot com
Target Milestone: ---
Created attachment 63160
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63160&action=edit
The preprocessed file using the "-save-temps" flag
I would like to report a potential infinite loop in the compilation of a
recursive function. I say "potential" since I waited ~20 seconds for the
compiler to finish and it did not; but I cannot prove that it is an infinite
loop because I did not look at gcc's code. Clang-19 also fails to compile the
code and displays the same behaviour, but this is not for you to fix; I think
it is worth to mention this just in case it helps you dismiss this report.
Moreover, and this is the most important bit, I would like you to bear in mind
that the code I'm trying to compile should *not* compile. Nevertheless, the
compiler should issue some error message. The following function is the one
that causes the infinite loop, and it is also the one that makes the program
"malformed":
<c++>
template <Bezier T, Bezier U>
[[nodiscard]] constexpr auto
interpolated_bezier_and_point(const T& l, const U& r, const size_t i) noexcept
{
auto b = l | r.get_point(i);
if (i == r.depth) {
return b;
}
return interpolated_bezier_and_point(b, r, i + 1);
}
</c++>
The function has two return statements each of which has a different type, so
this should not compile. It could be fixed by using "if constexpr {} + else {}"
but the point of this report is not how to fix the code (which I already know
how to do). Also, writing an "else" statement around the second return
statement does not have any effect in preventing the infinite loop.
GCC version: gcc (Ubuntu 14.2.0-4ubuntu2~24.04) 14.2.0
System type: Ubuntu 22.04.03 LTS -- ASUSTeK COMPUTER INC. X550VX -- Intel Core
i7-6700HQ
Options GCC was configured with: I installed gcc via apt package manager.
Compilation command:
All of the following commands lead to an infinite loop:
* g++ -g -Og -DDEBUG -D_GLIBCXX_DEBUG -Wall -Wextra -std=c++23
infinite_loop_gcc.cpp
* g++ -g -Og -DDEBUG -D_GLIBCXX_DEBUG -Wall -Wextra -std=c++20
infinite_loop_gcc.cpp
* g++ -std=c++23 infinite_loop_gcc.cpp
* g++ -std=c++20 infinite_loop_gcc.cpp
The C++ standard does not matter.
The compiler does not output any warnings / errors.
The flags -g -Og do not have any positive effect either.
N.B.: I generated the *.i* file with the last command listed above (plus
the -save-temps flag).
Compiler output (error messages, warnings, etc.): None