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

Improved macro handling in gcc #3327

Merged
merged 1 commit into from
Aug 29, 2020
Merged

Improved macro handling in gcc #3327

merged 1 commit into from
Aug 29, 2020

Conversation

Kimplul
Copy link
Contributor

@Kimplul Kimplul commented Aug 29, 2020

Here is the fix for #3320. I went with a solution where if the macro expansion error happens in the current file, set lnum and col accordingly. If the error happens in some other file, there's really no easy way to know on which line the error should be placed on in the current file, so just let lnum be 0.

For example, consider this situation:

/* c.cpp */
#include <string>
#include "header1.h"

int main(){
   return 0;
}
/* header1.h */
#include "header2.h"
/* header2.h */
std::string str = TEST;
# compile with
g++ c.cpp -DTEST='w'

The error reported by GCC would be

<command-line>: error: ‘w’ was not declared in this scope
header2.h:1:19: note: in expansion of macro ‘TEST’
    1 | std::string str = TEST;
      |                   ^~~~

To figure out on which line in c.cpp we should place the error we would need to go through the different headers in c.cpp until we find header2.h. I think that's a bit overkill, and just letting the lnum be zero with the text Error found in macro expansion. See :ALEDetail is (hopefully) good enough.

Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

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

Yep, this is good. We handle just this particular kind of error in this specific way, and it hopefully shouldn't break anything.

@w0rp w0rp merged commit 6b138b9 into dense-analysis:master Aug 29, 2020
@w0rp
Copy link
Member

w0rp commented Aug 29, 2020

Cheers! 🍻

@Kimplul
Copy link
Contributor Author

Kimplul commented Aug 29, 2020

Cheers! 🍺

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.

None yet

2 participants