This patch aims to improve the diagnostic to much better precision of indicating extern declaration being followed after static declaration rather than just generic non-static declaration.
Example Testcase: https://godbolt.org/z/zMTda6MGG
Differential D147888
Update declaration message of extern linkage Krishna-13-cyber on Apr 9 2023, 11:42 AM. Authored by
Details
This patch aims to improve the diagnostic to much better precision of indicating extern declaration being followed after static declaration rather than just generic non-static declaration. Example Testcase: https://godbolt.org/z/zMTda6MGG
Diff Detail
Event Timeline
Comment Actions I think we should fundamentally rethink this entire category of diagnostic. Rather than having a static diagnostic per offence stating what happened, we should instead have a single diagnostic that captures both what happened, why it's bad, and how to fix it. Something along the lines of error: 'x' has been declared with incompatible linkage specifiers (static and extern); please pick exactly one extern int x; ^~~~~~ note: previous definition here static int x; ^~~~~~ It'd also be more robust from an engineering perspective, since it means that we won't need to add new diagnostic permutations every time a new linkage specifier is added. Comment Actions I have tried a little modification from my side thinking on a beneficial note. I will make the changes to all the other test files as well if this diagnostic representation goes well after mentor review. For refactoring and restructuring the whole of the re-declaration would need some time I have been through it and would initiate another patch for that,In the concern of giving or having just one diagnostic for getting all cases of re-declaration would also need multiple conditional or switch statements inside our function block.At present we have the same with conditional statements taking care of each linkage but it has multiple permutations of diagnostic messages which is nice but can be improved.GCC differs only for this case of extern linkage which can be better/precise in clang where as others seem to be more precise in clang than former as I worked out with good number of test cases regarding this. Comment Actions Thanks for the ping! Does this require any further modification? Comment Actions I think the existing wording is pretty reasonable, changing "non-static declaration" into "extern declaration" isn't really giving the user any more information to help them resolve the issue. "please pick exactly one" doesn't seem likely to help the user either -- they already know there's a conflict, so picking one is already the solution the user is likely to have in mind. The hard part for the user is with figuring which one to pick, but we have no way to help them make that choice. So I'm not certain changes are needed in this space (I'm not opposed either), but I do think the idea @cjdb had to combine all these diagnostics into one using %select could be helpful. However, there are enough options that it could also be pretty complex to reason about. There's static, extern, and thread-local, as well as "non-" versions of each of those, so there are quite a few combinations. Comment Actions Yes I agree with this, Comment Actions I can sort of buy the argument that extern has a slight edge, but I think what would really help are test cases for all the various combinations so we can see them at once (static, extern. no linkage, thread local vs each counterpart). I'm concerned that the code you added conflicts with the existing code immediately below your changes and the standards wording quoted above your changes, but I left a comment on what would make me more comfortable.
|