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
HTSLIB_EXPORT pessimises clang error messages #1013
Comments
This can be worked around in several ways: extern HTSLIB_EXPORT htsFile *hts_open(const char *fn, const char *mode);
htsFile HTSLIB_EXPORT *hts_open(const char *fn, const char *mode);
HTSLIB_EXPORT_PRE
htsFile *hts_open(const char *fn, const char *mode) HTSLIB_EXPORT_POST; The first two make sure the first character is not part of the macro and put the interesting bit on the first line. In my limited testing on Windows and Illumos and reading of the The last one introduces an extra macro to go after the declaration, and htslib/hts_defs.h is rearranged so that the If the maintainers agree and have a preference for one of these transformations, I am happy to prepare a PR accordingly. I'm thinking probably the |
Indeed the All on one line without |
That is true, especially if we compress the two macros into one to reduce the spurious notes (and I'd toy with renaming it to
|
Actually I guess this ugly but shorter approach is also available (I always forget that we have newfangled preprocessor varargs now): // #ifdefs to select one of the following
#define HTS_EXPORT(...) __declspec(dllexport) __VA_ARGS__
#define HTS_EXPORT(...) __VA_ARGS__ __attribute__((__visibility__("default")))
HTS_EXPORT(htsFile *hts_open(const char *fn, const char *mode)); …never mind, that one's good for clang but makes GCC spell out the |
I think they were put on the line above mainly to stop the actual function definition from disappearing off to the right hand side of the screen. There was also an idea that you could easily find the exported functions using
|
When an HTSlib API function is called with the wrong number of arguments, extant Clang versions print spurious diagnostics showing how the HTSLIB_EXPORT macro was expanded. Reducing the number of macros involved improves samtools#1013.
This bug has now been fixed in mainline Clang, which will pinpoint the Unfortunately the fix missed the branch for the imminent release 10 by some weeks, so I guess it might turn up in macOS's system compiler as soon as WWDC in June 2021 (sigh…) but it's difficult to hazard a guess as Apple hasn't given any clues as to how Xcode's Clang corresponds to upstream LLVM versions for some years. However seeing as it will one day be fixed for Clang users, I'm now proposing to leave HTSlib's headers alone and just simplify the |
* Define HTSLIB_EXPORT without using a helper macro When an HTSlib API function is called with the wrong number of arguments, extant Clang versions print spurious diagnostics showing how the HTSLIB_EXPORT macro was expanded. Reducing the number of macros involved improves #1013. * Rename and remove helper macro.
Consider the following program, which misuses
hts_open()
:Compiling this with GCC produces an accurate error message:
However compiling it with Clang produces the following diagnostics:
Here the error message at bork.c:4 is accurate, but the notes showing you the location of the
hts_open
declaration are useless and voluminous.This inaccurate location for the declaration is surely a Clang bug; e.g., it was reported as bug 23564 in 2015, but sadly the lack of response on that bug report also gives you a clue as to how likely this is to be fixed in Clang any time soon.
To be precise, Clang is reporting the location of the declaration as the first character (post macro expansion) that is in any way a part of the declaration (and in our headers that is now on the line before the interesting one — the point of showing the declaration is to show you the parameters it was expecting), and more egregiously if that character is part of a macro expanding to something non-empty, it shows a trace of the macro expansions (which are irrelevant in this case).
The text was updated successfully, but these errors were encountered: