Bug 2259394 - GCC 14 fails to build magpie-wlr by not being able to find members of std namespace
Summary: GCC 14 fails to build magpie-wlr by not being able to find members of std nam...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: rawhide
Hardware: Unspecified
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Fedora Extras Quality Assurance
URL: https://github.com/BuddiesOfBudgie/ma...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-01-21 05:54 UTC by Neal Gompa
Modified: 2024-01-26 17:36 UTC (History)
13 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2024-01-21 11:31:53 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 109994 0 P3 NEW Issue a diagnostic when a C++ file defines a macro that hides a keyword 2024-01-21 22:23:27 UTC
GNU Compiler Collection 112293 0 P3 UNCONFIRMED Enhance error reporting with fix-it for missing <algorithm> in gcc 14 2024-01-21 20:50:12 UTC

Description Neal Gompa 2024-01-21 05:54:43 UTC
In upstream Budgie magpie v1 (Wayland compositor) development, the latest commits fail on Fedora Rawhide with some baffling errors about every method of the std namespace missing.

I was able to reproduce this in COPR as well[0] on x86_64[1] and AArch64[2].

This works on GCC 13[3][4], so I'm confused what's going on and I think GCC may be miscompiling things here.

[0]: https://copr.fedorainfracloud.org/coprs/ngompa/magpie-wlr/build/6926719/
[1]: https://download.copr.fedorainfracloud.org/results/ngompa/magpie-wlr/fedora-rawhide-x86_64/06926719-magpie-wlr/builder-live.log.gz
[2]: https://download.copr.fedorainfracloud.org/results/ngompa/magpie-wlr/fedora-rawhide-aarch64/06926719-magpie-wlr/builder-live.log.gz
[3]: https://download.copr.fedorainfracloud.org/results/ngompa/magpie-wlr/fedora-39-x86_64/06926719-magpie-wlr/builder-live.log.gz
[4]: https://download.copr.fedorainfracloud.org/results/ngompa/magpie-wlr/fedora-39-aarch64/06926719-magpie-wlr/builder-live.log.gz

Reproducible: Always

Steps to Reproduce:
1. Build magpie v1 (https://github.com/BuddiesOfBudgie/magpie/tree/v1) on Rawhide

Actual Results:  
Fails to build with errors about all the methods missing

Expected Results:  
Builds properly

Magpie v1 is a wlroots-based compositor written in C++ targeting C++20. In upstream CI and in COPR for Fedora, this is built against the wlroots package (currently at wlroots-0.17.1).

Comment 1 Florian Weimer 2024-01-21 11:31:53 UTC
My guess is that <stdlib.h> is no longer included before

#define namespace _namespace

in src/wlr-wrap-start.hpp, and is now implicitly included when that “namespace” macro definition is active. Since <stdlib.h> 

The workaround is to include <stdlib.h> before defining “namespace”:

diff --git a/src/wlr-wrap-start.hpp b/src/wlr-wrap-start.hpp
index 0ef0297..afd17b8 100644
--- a/src/wlr-wrap-start.hpp
+++ b/src/wlr-wrap-start.hpp
@@ -5,6 +5,7 @@ static_assert(0 == 1, "wlroots include wrap started and not ended");
 #define WLROOTS_INCLUDE_WRAP_STARTED
 
 #include <pthread.h>
+#include <stdlib.h>
 #include <wayland-server-core.h>
 
 #ifdef __clang__

Comment 2 Jonathan Wakely 2024-01-21 17:51:49 UTC
(In reply to Neal Gompa from comment #0)
> In upstream Budgie magpie v1 (Wayland compositor) development, the latest
> commits fail on Fedora Rawhide with some baffling errors about every method
> of the std namespace missing.

I don't think so.

The first error is:


../src/server.cpp: In member function ‘void Server::focus_view(View*, wlr_surface*)’:
../src/server.cpp:64:39: error: cannot convert ‘std::__cxx11::list<View*>::iterator’ to ‘const char*’
   64 |         (void) std::remove(views.begin(), views.end(), view);
      |                            ~~~~~~~~~~~^~
      |                                       |
      |                                       std::__cxx11::list<View*>::iterator


This happens when the std::remove algorithm from the <algorithm> header is not visible, but the std::remove(const char*) function from <cstdio> is declared. The problem is 100% guaranteed to be that <algorithm> was not included. See https://gcc.gnu.org/gcc-14/porting_to.html#header-dep-changes

The second error is:

In file included from ../src/xwayland.hpp:9,
                 from ../src/xwayland.cpp:1:
../src/wlr-wrap-start.hpp:16:19: error: ‘_namespace’ does not name a type
   16 | #define namespace _namespace
      |                   ^~~~~~~~~~

I have no idea what this is trying to do, but it's undefined behaviour to define a macro with the same name as a keyword. This code is bad and should feel bad.

Comment 3 Campbell Jones 2024-01-26 17:01:27 UTC
(In reply to Jonathan Wakely from comment #2)
> (In reply to Neal Gompa from comment #0)
> > In upstream Budgie magpie v1 (Wayland compositor) development, the latest
> > commits fail on Fedora Rawhide with some baffling errors about every method
> > of the std namespace missing.
> 
> I don't think so.
> 
> The first error is:
> 
> 
> ../src/server.cpp: In member function ‘void Server::focus_view(View*,
> wlr_surface*)’:
> ../src/server.cpp:64:39: error: cannot convert
> ‘std::__cxx11::list<View*>::iterator’ to ‘const char*’
>    64 |         (void) std::remove(views.begin(), views.end(), view);
>       |                            ~~~~~~~~~~~^~
>       |                                       |
>       |                                      
> std::__cxx11::list<View*>::iterator
> 
> 
> This happens when the std::remove algorithm from the <algorithm> header is
> not visible, but the std::remove(const char*) function from <cstdio> is
> declared. The problem is 100% guaranteed to be that <algorithm> was not
> included. See https://gcc.gnu.org/gcc-14/porting_to.html#header-dep-changes

You're correct, that error was caused by <algorithm> not being included. GCC 13 compiled that code just fine with <utility>, but I checked soon after this ticket was created and realized the mistake.

> The second error is:
> 
> In file included from ../src/xwayland.hpp:9,
>                  from ../src/xwayland.cpp:1:
> ../src/wlr-wrap-start.hpp:16:19: error: ‘_namespace’ does not name a type
>    16 | #define namespace _namespace
>       |                   ^~~~~~~~~~
> 
> I have no idea what this is trying to do, but it's undefined behaviour to
> define a macro with the same name as a keyword. This code is bad and should
> feel bad.

Believe me, I wouldn't have written it if it weren't necessary - it's there because the C code that wlr-wrap-start guards against uses "namespace" as a parameter name, so it has to be redefined temporarily to avoid compiler errors.

Comment 4 Campbell Jones 2024-01-26 17:08:43 UTC
(In reply to Florian Weimer from comment #1)
> My guess is that <stdlib.h> is no longer included before
> 
> #define namespace _namespace
> 
> in src/wlr-wrap-start.hpp, and is now implicitly included when that
> “namespace” macro definition is active. Since <stdlib.h> 
> 
> The workaround is to include <stdlib.h> before defining “namespace”:
> 
> diff --git a/src/wlr-wrap-start.hpp b/src/wlr-wrap-start.hpp
> index 0ef0297..afd17b8 100644
> --- a/src/wlr-wrap-start.hpp
> +++ b/src/wlr-wrap-start.hpp
> @@ -5,6 +5,7 @@ static_assert(0 == 1, "wlroots include wrap started and not
> ended");
>  #define WLROOTS_INCLUDE_WRAP_STARTED
>  
>  #include <pthread.h>
> +#include <stdlib.h>
>  #include <wayland-server-core.h>
>  
>  #ifdef __clang__

This fixed it, thanks.

Comment 5 Jonathan Wakely 2024-01-26 17:36:46 UTC
(In reply to Campbell Jones from comment #3)
> Believe me, I wouldn't have written it if it weren't necessary - it's there
> because the C code that wlr-wrap-start guards against uses "namespace" as a
> parameter name, so it has to be redefined temporarily to avoid compiler
> errors.

Oh yuck, that does seem unavoidable though.


Note You need to log in before you can comment on or make changes to this bug.