I had this thought from reading one of the other threads on here:
#include <string>
int main()
{
std::string s;
}
#include <cstdio>
#include <iostream>
struct Whatever
{
int z;
Whatever() [[construction_only_of_use]] { z = 0; std::cout << "Whatever!\n"; }
// If applied to the struct then however this type is constructed,
// it will be diagnosed as unused if no methods are called on it.
};
int main()
{
Whatever x; // Diagnose as unused. Use [[construction_only_of_use]] to prevent.
}
If we can already control construction only issues like I have described, I am not aware of how.
Compilers are already smart enough to optimize away code that never performs I/O, such as your example with std::string. https://godbolt.org/g/3mKNwn
-Ray
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/3e025662-c9e5-4e62-be32-2bf67b6be143%40isocpp.org.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f6996a18-db4c-b57c-77ea-7119a3e5145d%40gmail.com.
Er... well... as I recall, exactly that was the sticking problem in the
earlier conversation.
I suspect that the correct answer probably amounts to "a branch in the
code depended on the value of at least one member in <object-specific
set of members>". (IOW, sort of a converse of valgrind's "conditional
expression depends on value of uninitialized bytes".) That's hard to
specify. And it's worse when you only need to care #ifdef _DEBUG.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f6996a18-db4c-b57c-77ea-7119a3e5145d%40gmail.com.
I'd rather leave this "issue" alone; in systems where symmetrical behavior is required (loading a DLL / unloading it, for example), a simple way to automate unloading is using the destructor of a local (named) variable and let RAII work its magic. If a compiler warns about it at high warning levels, let it, but I'd keep the standard's text away.
We would need an attribute or something. Without that, the compiler
"must" assume that it is okay to merely construct and destroy the
object. (When I say "must"... it *could* make the opposite assumption,
but this would produce false positives, and vendors have historically
chosen to warn too little rather than too much. "Must" implies the
assumption that this choice will remain unchanged.)
--
Matthew
--If it were opt-in, do [[maybe_unused]] and [[nodiscard]] already cover it?Nevin ":-)" Liber <mailto:ne...@eviloverlord.com> +1-847-691-1404
On 2017-10-12 18:19, Matthew Woehlke wrote:
> On 2017-10-12 17:39, Nevin Liber wrote:
>> You want opt-out, which will generate far too many false positives on
>> existing, working code. For many businesses, changing existing, working
>> code has a very non-trivial cost.
>
> Opt-out by *adding an attribute*. If that's too hard... just turn the
> bloody warning off. Geez.
>
> The problem with opt-*in* is that 98% of classes would need to be annotated.
>
>> If it were opt-in, do [[maybe_unused]] and [[nodiscard]] already cover it?
>
> Not really; you'd have to annotate every *use* of a type that it is okay
> to keep in scope but not otherwise use. [[nodiscard]] is too broad a
> brush, and [[maybe_unused]] is to narrow. Plus [[nodiscard]] is opt-in,
> which is wrong per above.
--You want opt-out, which will generate far too many false positives on existing, working code. For many businesses, changing existing, working code has a very non-trivial cost.If it were opt-in, do [[maybe_unused]] and [[nodiscard]] already cover it?Nevin ":-)" Liber <mailto:ne...@eviloverlord.com> +1-847-691-1404
On 2017-10-12 21:56, gmis...@gmail.com wrote:
> We can't break any code from this feature, by default it does not affect
> optimization, so put the warnings on by default is my feeling.
The reason not to enable the warning by default is that a) it will
result in new warnings in existing code, and b) some people build with
-Werror (and/or the MSVC equivalent). This is what folks are talking
about when they express concern that this would "break" existing code.
However, this all is somewhat beside the point, because it has no impact
on the standard, which does not specify warnings. Ultimately, it is the
vendors that will decide what is best for their customers as to whether
to warn by default or not.