<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 31 October 2013 11:16, Christopher Jefferson <span dir="ltr"><<a href="mailto:chris@bubblescope.net" target="_blank">chris@bubblescope.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Me and my wife teach C and C++ at Scottish Universities. I asked her<br>
what is the most important bit of UB she would like to see removed to<br>
make C++ easier to teach. Her suggestion (which I agree with) is how<br>
easy it is to no initialise variables, both in classes and on the<br>
stack. There are 2 main current ways I am aware of detecting UB from<br>
uninitalised variables:<br>
<br>
1) Many compilers warn about stack variables being read before they<br>
are written to, with an appropriate warning level (but none provide<br>
these warnings with no warning flag, and some deductions require<br>
optimisation, which then means you have to compile twice to get a<br>
debugging version)<br>
<br>
2) Tools like 'valgrind' will warn of more variable misuses.<br>
<br>
However, Rightly or wrongly, students will not use these tools<br>
correctly, and will get difficult to fix bugs.<br>
<br>
Her suggested fix is to introduce a new notation for constructors<br>
which means "I am not initialising this member on purpose". This will<br>
allow compilers to then add a warning at a high warning level that a<br>
member is missed from a constructor.<br>
<br>
I also wonder, what is people's opinion on telling students from day 1<br>
of a C++ class to always run their programs through valgrind, even<br>
their first "hello world" program? This would help them catch a much<br>
wider range of bugs earlier, but also teaches them a safety net they<br>
may come to excessively rely on.<br>
<br>
Chris<br>
_______________________________________________<br>
ub mailing list<br>
<a href="mailto:ub@isocpp.open-std.org">ub@isocpp.open-std.org</a><br>
<a href="http://www.open-std.org/mailman/listinfo/ub" target="_blank">http://www.open-std.org/mailman/listinfo/ub</a><br>
</blockquote></div><br></div><div class="gmail_extra">We have had discussions about this, in at least <span class="">c++std-ext-12346<br></span></div><div class="gmail_extra"><span class="">and probably in some core reflector discussions as well.<br>
<br></span></div><div class="gmail_extra"><span class="">I don't think telling people to run valgrind is good advice. I think building<br>with ubsan is better advice. I'd like to have a safer default, but I don't<br>
think we can have it due to its breaking existing code.<br></span></div></div>