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 fixes after previous C++ patch #1935

Merged
merged 4 commits into from
Jul 21, 2017
Merged

Build fixes after previous C++ patch #1935

merged 4 commits into from
Jul 21, 2017

Conversation

mike-lischke
Copy link
Member

This patch is for the C++ target only and contains fixes for compilation problems in VS and XCode after merging the last C++ patch. There is no functional change.

mike-lischke and others added 3 commits July 1, 2017 19:30
VS 2013 doesn't accept certain C++11 constants like std::numeric_limits, so we have to return to the code used before that mentioned patch.
@@ -11,7 +11,7 @@ namespace antlr4 {

class ANTLR4CPP_PUBLIC Recognizer {
public:
static const size_t EOF = std::numeric_limits<size_t>::max();
static const size_t EOF = (size_t)-1; // std::numeric_limits<size_t>::max(); doesn't work in VS 2013.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use static_cast<size_t>(-1) as an alternative? (here are elsewhere where there are old-style casts in this patch.)

Also: there is the INVALID_INDEX #define at the end of antlr-common.h, which uses the same construct. Does VS2013 choke on use of that as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly doable, I just like to avoid lengthy cast expressions in simple cases like this (it's probably optimized away by the compiler).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither type of cast will be have any runtime overhead. The reason I prefer static_cast over a C-style cast is that the compiler enforces that the cast is safe. That way, when examining code, you only need to look for occurrences of reinterpret_cast to check for potential unsafe casting. This is also a rule on one of Scott Meyer's "Effective C++" books.

@mike-lischke
Copy link
Member Author

@parrt Please merge this C++-only patch. People try to build from master and it fails due do missing project settings on Windows.

@parrt parrt added this to the 4.7.1 milestone Jul 21, 2017
@parrt parrt merged commit 2d6a494 into antlr:master Jul 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants