<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><span class="vcard"><a class="email" href="mailto:aaron@aaronballman.com" title="Aaron Ballman <aaron@aaronballman.com>"> <span class="fn">Aaron Ballman</span></a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED WONTFIX - clang-6: __has_cpp_attribute(nodiscard) == true with -std=c++14, but warns about usage with -pedantic"
href="https://bugs.llvm.org/show_bug.cgi?id=43743">bug 43743</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>---
</td>
<td>WONTFIX
</td>
</tr>
<tr>
<td style="text-align:right;">CC</td>
<td>
</td>
<td>aaron@aaronballman.com
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED WONTFIX - clang-6: __has_cpp_attribute(nodiscard) == true with -std=c++14, but warns about usage with -pedantic"
href="https://bugs.llvm.org/show_bug.cgi?id=43743#c3">Comment # 3</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED WONTFIX - clang-6: __has_cpp_attribute(nodiscard) == true with -std=c++14, but warns about usage with -pedantic"
href="https://bugs.llvm.org/show_bug.cgi?id=43743">bug 43743</a>
from <span class="vcard"><a class="email" href="mailto:aaron@aaronballman.com" title="Aaron Ballman <aaron@aaronballman.com>"> <span class="fn">Aaron Ballman</span></a>
</span></b>
<pre>(In reply to Hans Dembinski from <a href="show_bug.cgi?id=43743#c2">comment #2</a>)
<span class="quote">> In Boost, we have a macro that expands to [[nodiscard]] when the attribute
> is supported, but the macro should not raise any warnings, -pedantic or not.
> So far we are checking
>
> #if __has_cpp_attribute(nodiscard) ...
>
> But maybe that is simply not how feature detection is supposed to work.
> After reading <a href="https://en.cppreference.com/w/cpp/feature_test">https://en.cppreference.com/w/cpp/feature_test</a> I learned that
> __has_cpp_attribute(nodiscard) does not return simply true or false, but the
> date when the feature was added to the C++ standard.
>
> So to get the desired behavior in Boost, we should probably do
>
> #if __cplusplus > __has_cpp_attribute(nodiscard) ...
>
> The branch is then taken only if the C++ version is high enough to
> officially include [[nodiscard]].
>
> Would that make sense?</span >
Feature testing macros only tell you if the compiler knows about the feature,
not whether the feature can be used without diagnostics. If you want to test
whether the compiler knows about the nodiscard attribute at all, you would use
`#if __has_cpp_attribute(nodiscard)`. If you want to test whether the compiler
knows about the nodiscard attribute where nodiscard can accept an optional
string-literal message, you would use `#if __has_cpp_attribute(nodiscard) >=
201907L` -- the date value returned tells you what additional functionality is
supported.
Using `#if __cplusplus > __has_cpp_attribute(nodiscard)` would work most of the
time but could fail in two circumstances I can think of: 0) when the attribute
date returned is the same as the date used by __cplusplus and 1) when the
attribute is known to Clang but doesn't conform to the standard. In that case,
we will often use a value that's less than what's specified in
<a href="http://eel.is/c++draft/cpp#tab:cpp.cond.ha">http://eel.is/c++draft/cpp#tab:cpp.cond.ha</a> (for instance, we're doing that with
the [[likely]] and [[unlikely]] attributes while fleshing out the
implementation). Neither of these circumstances apply for nodiscard in Clang,
but could apply to other attributes.
I am resolving this as WONTFIX because I think the current behavior is correct.
If there's strong sentiment that we should reconsider that, feel free to reopen
the bug with more details.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>