-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Compile error with Intel C++ compiler and "constexpr" #2736
Comments
If the Removing the |
If 2 compilers (clang, icc) does not accept that code, maybe it's wrong? |
I'm no C++ guru, and the information I've found online on this topic is about as clear as mud. This is the closest I've got: However, it does appear that there can be cases where a |
Another one from stackoverflow: |
|
Signed-off-by: Stefan Weil <sw@weilnetz.de>
Thank you. Fixed in commit ca87b06. |
I don't understand. Is the code correct, and both the Clang and Intel compilers are erroring out spuriously? (I can submit an issue to Intel, if need be.) It's not clear that this C++ usage is correct, and the Stack Overflow link that @amitdo posted implies that G++ accepts it only due to a non-conforming extension. If the desire is to take advantage of a GNU extension, then the code at issue should be enclosed in a |
I'd welcome code which works with any modern compiler and which does the same. The goal is to calculate two lookup tables at compile time instead of wasting time during execution. This works perfectly with the GNU compiler:
Here the result with clang which needs code to fill the tables at runtime:
|
I completely agree that such an optimization is desirable. The problem is, the current implementation is not valid C++14/C++17 code, and only works with G++ due to a GNU extension---yet this is conditionalized in the code as though it were a limitation of the Clang and Intel compilers. If and when someone tries to build Tesseract using some other modern/conforming C++ compiler, they're going to encounter the same issue, and by this pattern yet another I don't know C++ well enough to suggest the Right Way(tm) of doing this initialization (after some more reading, it's not clear to me that such a way even exists at this point in time), but I would say, if you're going to rely on a GNU extension, then own up to it---conditionalize that code so that only |
In the last hour I have read a bit more on this topic. The code is valid C++14 code for all compilers which handle the functions The current implementation with the growing list of cases which don't use the optimal code is the result of a software evolution. We want the optimal code. If we'd change the implementation to restrict the optimal code to g++, we might miss other compilers which support it. And we would miss the fact that some compilers don't use the optimal code. To solve this dilemma, we could add a feature check to the configure script. Or we could generate the source code for constant lookup tables, either by a small Python script or by a simple C program. Such generated source code would even work with any ANSI C compiler. |
Have you looked at that first Stack Overflow link I posted ("Is it a conforming compiler extension to treat non-constexpr standard library functions as constexpr?")? Not only does it appear that the standard math-library functions are explicitly not allowed to be constexpr, it seems there is some possibility that G++'s non-conformance on this point may be dialed back in the future (though that discussion dates from 2014, so perhaps it has been superseded). Given that at present, G++ builds are the only known beneficiaries of this optimization, I believe taking the "classic" approach of generating the table via an external script (and sidestepping the whole C++ standards-conformance issue) would be a good way to go. In my experience, it's certainly possible for code to be too modern for its own good... |
The code for the classic approach is much shorter than the whole discussion here, even shorter than your comment. I'll send a pull request for it tomorrow. |
I'm not surprised that the discussion outweighs the code :-] Thank you Stefan, I appreciate this solution which will allow all modern C++ compilers to benefit from the optimization. |
Signed-off-by: Stefan Weil <sw@weilnetz.de>
FYI, Intel C/C++ compilers complete adoption of LLVM I know It does not matter for this issue because the code in #2740 is compiler independent. |
Environment
Current Behavior:
I am compiling Tesseract using the Intel C++ compiler, version 19.0.1.144, and encounter the following build error:
This is with
-std=c++17
. The following edits allow source compilation to proceed:Alternately, compiling with
-std=c++11
also allows compilation to succeed.Expected Behavior:
This issue appears similar to #2246, but I do not believe it is the result of a shortcoming in the Intel compiler. (The compiler supports up to C++17, and in our experience has been stricter about conformance than G++.)
Suggested Fix:
I am not familiar with this C++ usage, but will be happy to test any changes.
The text was updated successfully, but these errors were encountered: