Skip to content

Conversation

@CarlosNihelton
Copy link
Contributor

GCC 12.2 is not convinced that dir will never be empty.

Since that's an exceptional situation that seems almost impossible to happen, I'm throwing an exception here.

Fixes #160

GCC 12.2 is not convinced that dir will never be empty.
Since that's an exceptional situation that seems almost impossible to
happen, I'm throwing an exception here.

Fixes standardese#160
Copy link
Collaborator

@foonathan foonathan left a comment

Choose a reason for hiding this comment

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

Thanks, but I disagree about the fix.

return file;
if (dir.empty())
// should never happen, but GCC 12.2 is not convinced. That's what exceptions are for, isn't it?
throw std::invalid_argument("Either file is absolute or relative to some named dir");
Copy link
Collaborator

Choose a reason for hiding this comment

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

No, that's what assertions are for ;)

Please assert instead at the beginning of the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Assertion was not enough, so I had to place a #pragma. Not as beautiful but at least one can easily spot that the line would be unreachable if dir was empty (unless clever users decides to disable the asserts, then they would be on their own luck :) )

A pragma was necessary, though. GCC up to 12.2 cannot understand the
macro DEBUG_ASSERT would have stopped the execution before the suspected
line.
@foonathan
Copy link
Collaborator

I didn't like the pragma, so I've just decided to support empty paths. Thanks for the PR, but it was quicker to do it myself :D

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.

GCC array bounds complain on libclang_parser.cpp

2 participants