g-truc / glm

OpenGL Mathematics (GLM)
https://glm.g-truc.net
Other
9.05k stars 2.1k forks source link

Build fails with clang on GLM_DEPRECATED GLM_FUNC_DECL construct #1269

Closed AMDmi3 closed 4 months ago

AMDmi3 commented 5 months ago

I've ran into this when build-testing one of glm consumers, gamescope, before updating FreeBSD port of glm to 1.x.

c++ -Isrc/gamescope_color_tests.p -Isrc -I../src -I/usr/local/include -fdiagnostics-color=never -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=c++20 -DWLR_USE_UNSTABLE -Wno-unused-parameter -Wno-missing-f
ield-initializers -Wno-c99-designator -Wno-invalid-offsetof -Wno-unused-const-variable -Wno-deprecated-volatile -Wno-ignored-qualifiers -Wno-missing-braces -ffast-math -DHAVE_PIPEWIRE=1 -DHAVE_OPENVR=0 '-DHWDATA_P
NP_IDS="//usr/local/share/hwdata/hwdata/pnp.ids"' -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -DGLM_ENABLE_EXPERIMENTAL -MD -MQ src/gamescope_color_tests.p/color_tests.cpp.o -MF src/gamescope_color_tes
ts.p/color_tests.cpp.o.d -o src/gamescope_color_tests.p/color_tests.cpp.o -c ../src/color_tests.cpp
In file included from ../src/color_tests.cpp:4:
In file included from /usr/local/include/glm/ext.hpp:198:
/usr/local/include/glm/./gtx/bit.hpp:49:17: error: 'nodiscard' attribute cannot be applied to types
        GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoAbove(genIUType Value);
                       ^
/usr/local/include/glm/./ext/../detail/setup.hpp:498:23: note: expanded from macro 'GLM_FUNC_DECL'
#define GLM_FUNC_DECL GLM_NODISCARD GLM_CUDA_FUNC_DECL
                      ^
/usr/local/include/glm/./ext/../detail/setup.hpp:344:26: note: expanded from macro 'GLM_NODISCARD'
#       define GLM_NODISCARD [[nodiscard]]
                               ^

Reproducible with

#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/bit.hpp>

What preprocessed line looks like:

__attribute__((__deprecated__)) [[nodiscard]] genIUType powerOfTwoAbove(genIUType Value);

Smaller repro (note that template is required):

template<class T> __attribute__((__deprecated__)) [[nodiscard]] int foo(T t);
% clang++-14 -std=c++20  -c 1.cc 
1.cc:1:51: error: an attribute list cannot appear here
template<class T> __attribute__((__deprecated__)) [[nodiscard]] int foo(T t);
                                                  ^~~~~~~~~~~~~
1 error generated.

I haven't dug into the docs, but simple experiment revealed two ways to fix it: either change the order of attributes or use attributes of the same format, e.g. change __attribute__((__deprecated__)) to [[deprecated]. Both compile by gcc and clang, and I suggest to use [[deprecated]] in glm, as it's standard and supported since c++14.

pemsley commented 5 months ago

My builds are failing too, I think it's because Homebrew has moved to version 1.0.1

https://github.com/pemsley/coot/actions/workflows/build-coot-macos.yml

In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.h:15:
In file included from /usr/local/include/glm/ext.hpp:198:
/usr/local/include/glm/./gtx/bit.hpp:49:17: error: 'nodiscard' attribute cannot be applied to types
        GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoAbove(genIUType Value);
                       ^
/usr/local/include/glm/detail/setup.hpp:498:23: note: expanded from macro 'GLM_FUNC_DECL'
#define GLM_FUNC_DECL GLM_NODISCARD GLM_CUDA_FUNC_DECL
                      ^
/usr/local/include/glm/detail/setup.hpp:344:26: note: expanded from macro 'GLM_NODISCARD'
#       define GLM_NODISCARD [[nodiscard]]
                               ^
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.cpp:10:
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.h:15:
In file included from /usr/local/include/glm/ext.hpp:198:
/usr/local/include/glm/./gtx/bit.hpp:57:17: error: 'nodiscard' attribute cannot be applied to types
        GLM_DEPRECATED GLM_FUNC_DECL vec<L, T, Q> powerOfTwoAbove(vec<L, T, Q> const& value);
                       ^
/usr/local/include/glm/detail/setup.hpp:498:23: note: expanded from macro 'GLM_FUNC_DECL'
#define GLM_FUNC_DECL GLM_NODISCARD GLM_CUDA_FUNC_DECL
                      ^
/usr/local/include/glm/detail/setup.hpp:344:26: note: expanded from macro 'GLM_NODISCARD'
#       define GLM_NODISCARD [[nodiscard]]
                               ^
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.cpp:10:
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.h:15:
In file included from /usr/local/include/glm/ext.hpp:198:
/usr/local/include/glm/./gtx/bit.hpp:65:17: error: 'nodiscard' attribute cannot be applied to types
        GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoBelow(genIUType Value);
                       ^
/usr/local/include/glm/detail/setup.hpp:498:23: note: expanded from macro 'GLM_FUNC_DECL'
#define GLM_FUNC_DECL GLM_NODISCARD GLM_CUDA_FUNC_DECL
                      ^
/usr/local/include/glm/detail/setup.hpp:344:26: note: expanded from macro 'GLM_NODISCARD'
#       define GLM_NODISCARD [[nodiscard]]
                               ^
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.cpp:10:
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.h:15:
In file included from /usr/local/include/glm/ext.hpp:198:
/usr/local/include/glm/./gtx/bit.hpp:73:17: error: 'nodiscard' attribute cannot be applied to types
        GLM_DEPRECATED GLM_FUNC_DECL vec<L, T, Q> powerOfTwoBelow(vec<L, T, Q> const& value);
                       ^
/usr/local/include/glm/detail/setup.hpp:498:23: note: expanded from macro 'GLM_FUNC_DECL'
#define GLM_FUNC_DECL GLM_NODISCARD GLM_CUDA_FUNC_DECL
                      ^
/usr/local/include/glm/detail/setup.hpp:344:26: note: expanded from macro 'GLM_NODISCARD'
#       define GLM_NODISCARD [[nodiscard]]
                               ^
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.cpp:10:
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.h:15:
In file included from /usr/local/include/glm/ext.hpp:198:
/usr/local/include/glm/./gtx/bit.hpp:81:17: error: 'nodiscard' attribute cannot be applied to types
        GLM_DEPRECATED GLM_FUNC_DECL genIUType powerOfTwoNearest(genIUType Value);
                       ^
/usr/local/include/glm/detail/setup.hpp:498:23: note: expanded from macro 'GLM_FUNC_DECL'
#define GLM_FUNC_DECL GLM_NODISCARD GLM_CUDA_FUNC_DECL
                      ^
/usr/local/include/glm/detail/setup.hpp:344:26: note: expanded from macro 'GLM_NODISCARD'
#       define GLM_NODISCARD [[nodiscard]]
                               ^
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.cpp:10:
In file included from ../../../coot/MoleculesToTriangles/CXXClasses/RepresentationInstance.h:15:
In file included from /usr/local/include/glm/ext.hpp:198:
/usr/local/include/glm/./gtx/bit.hpp:89:17: error: 'nodiscard' attribute cannot be applied to types
        GLM_DEPRECATED GLM_FUNC_DECL vec<L, T, Q> powerOfTwoNearest(vec<L, T, Q> const& value);
                       ^
/usr/local/include/glm/detail/setup.hpp:498:23: note: expanded from macro 'GLM_FUNC_DECL'
#define GLM_FUNC_DECL GLM_NODISCARD GLM_CUDA_FUNC_DECL
                      ^
/usr/local/include/glm/detail/setup.hpp:344:26: note: expanded from macro 'GLM_NODISCARD'
#       define GLM_NODISCARD [[nodiscard]]
                               ^
6 errors generated.
make[2]: *** [libMoleculesToTrianglesCXXClasses_la-RepresentationInstance.lo] Error 1
tobbi commented 4 months ago

https://github.com/g-truc/glm/pull/1252 was where [[nodiscard]] was added. @christophe-lunarg Can you take a look at this please?

tobbi commented 4 months ago

I hope the above PR fixes this.

tobbi commented 4 months ago

@christophe-lunarg When are you gonna release a new version of GLM? The SuperTux project relies on GLM for some maths and we're currently using an earlier version in the nightly builds and would like to use a current upstream version.