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

Build error in include/nana/deploy.hpp redefinition of clamp #220

Closed
Red-Portal opened this issue Jun 25, 2017 · 9 comments
Closed

Build error in include/nana/deploy.hpp redefinition of clamp #220

Red-Portal opened this issue Jun 25, 2017 · 9 comments

Comments

@Red-Portal
Copy link
Contributor

while building with gcc 7 I got this error

[ 98%] Building CXX object CMakeFiles/BoardPlatformerClient.dir/main.cpp.o
In file included from /usr/include/c++/7.1.1/functional:64:0,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/gui/detail/general_events.hpp:21,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/gui/programming_interface.hpp:17,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/gui/wvl.hpp:18,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/gui.hpp:1,
                 from /home/msca8h/projects/board_platformer/src/client/main.cpp:1:
/usr/include/c++/7.1.1/bits/stl_algo.h:3719:5: error: redefinition of ‘template<class _Tp> constexpr const _Tp& std::clamp(const _Tp&, const _Tp&, const _Tp&)’
     clamp(const _Tp& __val, const _Tp& __lo, const _Tp& __hi)
     ^~~~~
In file included from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/deploy.hpp:20:0,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/paint/../basic_types.hpp:16,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/paint/graphics.hpp:18,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/gui/effects.hpp:15,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/gui/programming_interface.hpp:16,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/gui/wvl.hpp:18,
                 from /home/msca8h/projects/board_platformer/src/client/nana/include/nana/gui.hpp:1,
                 from /home/msca8h/projects/board_platformer/src/client/main.cpp:1:
/home/msca8h/projects/board_platformer/src/client/nana/include/nana/stdc++.hpp:151:21: note: ‘template<class T> constexpr const T& std::clamp(const T&, const T&, const T&)’ previously declared here
  constexpr const T& clamp(const T& v, const T& lo, const T& hi)
                     ^~~~~
make[2]: *** [CMakeFiles/BoardPlatformerClient.dir/build.make:63: CMakeFiles/BoardPlatformerClient.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/BoardPlatformerClient.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

is this because I'm using a new compiler?
or compiler flags perhaps?

@Red-Portal Red-Portal changed the title Error in include/nana/deploy.hpp redefinition of clamp Build error in include/nana/deploy.hpp redefinition of clamp Jun 25, 2017
@cnjinhao
Copy link
Owner

Yes, because of new compiler.

The detection of std::clamp in c++defines.hpp

#if (!defined(__cpp_lib_clamp)) || (__cpp_lib_clamp < 201603)
#	ifndef _enable_std_clamp
#		define _enable_std_clamp
#	endif
#endif

@Red-Portal
Copy link
Contributor Author

Should I open a PR fix for that?

@cnjinhao
Copy link
Owner

That's would be great. Thanks in advance.

@Red-Portal
Copy link
Contributor Author

Alright I'll work on that

@Red-Portal
Copy link
Contributor Author

#222 fixed

@codicodi
Copy link
Contributor

codicodi commented Jul 1, 2017

Similar error occurs with VS2017 when compiling with /std:c++latest:

c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\algorithm(4033,2): error C2995: 'const T &std::clamp(const T &,const T &,const T &)': function template has already been defined

Wouldn't it be better to define custom 'clamp' in namespace nana? Defining stuff is in namespace std is undefined behaviour according to the C++ standard and breaks compilation as soon as compiler starts to conform to c++17 :(

@cnjinhao
Copy link
Owner

cnjinhao commented Jul 2, 2017

Hi, @codicodi
Thank you for reporting this issue, the bug is fixed now.

I know the restriction that C++ standard describes. Essentially, I am not trying to introduce new customized names into the namespace std, but the unimplemented standard compenent. The purpose of defining clamp in namespace std is to avoid creating a duplicate with standard. But to reduce the complexity, there are some other unimplemented standard compenents are defined in namespace nana, such as filesystem, any and optional.

@Red-Portal
Copy link
Contributor Author

Red-Portal commented Jul 3, 2017

Maybe making a macro switch such as

#if C++17
     #define nana::clamp std::clamp
#else
     #define enable_nana_clamp
#endif

Would do the job?
Though we'll have to change all references to std::clamp to nana::clamp.
I guess this would solve your concern

@cnjinhao
Copy link
Owner

cnjinhao commented Jul 3, 2017

Thank you for the suggestion, this way is used for adopting nana::file system to std::experimental::filesystem.
The conflict is generated because of failure of feature test. Now it is fixed.

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

No branches or pull requests

3 participants