Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLM_FORCE_PURE doesn't work with C++11 after 68c7e7e50b #832

Closed
johnbeard opened this issue Nov 6, 2018 · 6 comments
Closed

GLM_FORCE_PURE doesn't work with C++11 after 68c7e7e50b #832

johnbeard opened this issue Nov 6, 2018 · 6 comments
Assignees
Labels
Milestone

Comments

@johnbeard
Copy link

johnbeard commented Nov 6, 2018

After upgrading to 0.9.9.3 (Arch), code which sets GLM_FORCE_PURE can no longer be built. This includes, for example, KiCad.

Reverting 68c7e7e fixes it. This only occurs with C++11 (i.e. constexpr is available) and if GLM_FORCE_PURE is defined. C++14 works.

Attached is a simple example that doesn't compile.

Sample compilation error:

/usr/lib/ccache/bin/c++    -std=c++11 -o CMakeFiles/glm_test.dir/main.cpp.o -c /home/john/temp/glm-test/main.cpp
In file included from /usr/include/glm/ext/vector_bool2.hpp:5,
                 from /usr/include/glm/vec2.hpp:5,
                 from /usr/include/glm/glm.hpp:116,
                 from /home/john/temp/glm-test/main.cpp:6:
/usr/include/glm/detail/type_vec2.hpp:90:40: error: ‘constexpr const T& glm::vec<2, T, Q>::operator[](glm::vec<2, T, Q
>::length_type) const’ cannot be overloaded with ‘constexpr T& glm::vec<2, T, Q>::operator[](glm::vec<2, T, Q>::length
_type) const’
   GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;
                                        ^~~~~~~~
/usr/include/glm/detail/type_vec2.hpp:89:34: note: previous declaration ‘constexpr T& glm::vec<2, T, Q>::operator[](gl
m::vec<2, T, Q>::length_type) const’
   GLM_FUNC_DECL GLM_CONSTEXPR T& operator[](length_type i);

err.txt
glm_test.tar.gz

@johnbeard
Copy link
Author

johnbeard commented Nov 13, 2018

The issue here is a difference in what constexpr means in C++11 and C++14 onwards:

So this means that:

GLM_FUNC_DECL GLM_CONSTEXPR T& operator[](length_type i);
GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;

Becomes, in C++11:

 constexpr T& operator[](length_type i) const;    // const is implicit here
 constexpr const T& operator[](length_type i) const;

Which differs only in return type.

In C++14 onwards, it's OK, there is a a const/non-const to differentiate the two:

 constexpr T& operator[](length_type i);
 constexpr const T& operator[](length_type i) const;

I'm not sure exactly what the logic in setup.hpp should be. I don't think any C++ versions under C++14 should be using constexpr on NSMFs where the only difference between two is const and the the return type (because the const will be implied). How the Intel and VC compilers handle this, I don't know.

glm/glm/detail/setup.hpp

Lines 281 to 288 in ddebaba

#elif (GLM_LANG & GLM_LANG_CXX14_FLAG)
# define GLM_HAS_CONSTEXPR 1
#else
# define GLM_HAS_CONSTEXPR ((GLM_LANG & GLM_LANG_CXX0X_FLAG) && GLM_HAS_INITIALIZER_LISTS && (\
((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_COMPILER >= GLM_COMPILER_INTEL17)) || \
((GLM_COMPILER & GLM_COMPILER_GCC) && (GLM_COMPILER >= GLM_COMPILER_GCC6)) || \
((GLM_COMPILER & GLM_COMPILER_VC) && (GLM_COMPILER >= GLM_COMPILER_VC15))))
#endif

@walkthetalk
Copy link

is there any workaround?

@stef
Copy link

stef commented Feb 18, 2019

is there any workaround?

you could revert 68c7e7e

@johnbeard
Copy link
Author

You can also build with C++14 or later or unset GLM_FORCE_PURE (but this may have implications for portability, I think).

@Groovounet
Copy link
Member

This issue should be fixed in the master branch for GLM 0.9.9.4 release.

Thanks for reporting

@stef
Copy link

stef commented Mar 1, 2019

thanks for fixing! do you have an estimate when 0.9.9.4 will come out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants