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

BUG: fix a bug for clang. #9

Closed

Conversation

JianCheng
Copy link

There is a bug when building exprtk with clang.

Const type without a user-provided default constructor.
https://stackoverflow.com/questions/26077807/why-does-gcc-allow-a-const-object-without-a-user-declared-default-constructor-bu

@ArashPartow
Copy link
Owner

@JianCheng What version of Clang are you using and what were the compiler options used to generate the error you're seeing?

@JianCheng
Copy link
Author

Hi @ArashPartow . I am using clang 3.7.0 in fedora 23.
When I run

clang -pedantic-errors -Wall -Wextra -Werror -Wno-long-long -O1 -o exprtk_test exprtk_test.cpp -L/usr/lib -lstdc++ -lm

it shows

In file included from exprtk_test.cpp:29:
./exprtk.hpp:1965:64: error: default initialization of an object of const type 'const typename numeric::details::number_type<double>::type'
      (aka 'const exprtk::details::numeric::details::real_type_tag') without a user-provided default constructor
         const typename numeric::details::number_type<T>::type num_type;
                                                               ^
                                                                        = {}

@ArashPartow
Copy link
Owner

@JianCheng I was not able to reproduce the error, using the most recent clang:

~/workspace/exprtk $ clang --version
clang version 6.0.0 (trunk 314852)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

Building for C++11, C++14 and C++17:

~/workspace/exprtk $ make exprtk_test 
clang -pedantic-errors -Wall -Wextra -Werror -Wno-long-long -O2 -std=c++11 -o exprtk_test exprtk_test.cpp -L/usr/lib -lstdc++ -lm
~/workspace/exprtk $ make exprtk_test 
clang -pedantic-errors -Wall -Wextra -Werror -Wno-long-long -O2 -std=c++14 -o exprtk_test exprtk_test.cpp -L/usr/lib -lstdc++ -lm
~/workspace/exprtk $ make exprtk_test 
clang -pedantic-errors -Wall -Wextra -Werror -Wno-long-long -O2 -std=c++17 -o exprtk_test exprtk_test.cpp -L/usr/lib -lstdc++ -lm

@ArashPartow ArashPartow closed this Oct 3, 2017
@JianCheng
Copy link
Author

Maybe the newer version of clang fixed it.
When I use clang 3.7 in fedora 23 with c++11, it shows:

[jcheng@W541 exprtk]$ clang++ -pedantic-errors -Wall -Wextra -Werror -Wno-long-long -O1 -o aa exprtk_simple_example_01.cpp -L/usr/lib -lstdc++ -lm -std=c++11 
In file included from exprtk_simple_example_01.cpp:21:
./exprtk.hpp:1965:64: error: default initialization of an object of const type 'const typename numeric::details::number_type<double>::type'
      (aka 'const exprtk::details::numeric::details::real_type_tag') without a user-provided default constructor
         const typename numeric::details::number_type<T>::type num_type;
                                                               ^
                                                                       {}
./exprtk.hpp:3460:41: note: in instantiation of function template specialization 'exprtk::details::string_to_real<double>' requested here
                  if (!exprtk::details::string_to_real(t.value,v))
                                        ^
1 error generated.
[jcheng@W541 exprtk]$ clang --version
clang version 3.7.0 (tags/RELEASE_370/final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
[jcheng@W541 exprtk]$ uname -av
Linux W541 4.2.8-300.fc23.x86_64 #1 SMP Tue Dec 15 16:49:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

@ArashPartow
Copy link
Owner

ArashPartow commented Oct 4, 2017

@JianCheng Note that the 'type' class is an empty type. The issue of an uninitialized const instance occurs when a class that has members is being instantiated and no constructor is provided - the question becomes what use is such as class as it's members are not initialized and will hence possibly cause UB when used, and it is const so there is no way to modify/initialise the members after construction.

That being said, I've now retested it with Clang 4.7, GCC 4.8 - 7.1, MSVC 10-14 and they all compile error and warning free.

@ArashPartow
Copy link
Owner

ArashPartow commented Dec 1, 2017

@JianCheng I've made changes to ExprTk that should now allow for older versions of Clang to build error and warning free.

In short the problem seems to be related to DR-253. In the given context an error should be thrown iff the class/struct has members, otherwise if it is empty (by design for compile-time tag dispatch purposes) the compiler should not raise that particular diagnostic (either warning or error).


If possible, give the most recent version a go and if you find any issues do let me know.

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

Successfully merging this pull request may close these issues.

2 participants