[cfe-dev] Refs are assumed not-null. How to disable?

David Blaikie dblaikie at gmail.com
Fri May 30 11:06:16 PDT 2014


On Fri, May 30, 2014 at 10:28 AM, Óscar Fuentes <ofv at wanadoo.es> wrote:
> With optmizations on, the `return' on this code:
>
> bool foo(int &k) {
>   return &k != nullptr;
> }
>
> is reduced to `return true;'.
>
> Is there an option for disabling this optimization?

Nope, this was committed in
http://llvm.org/viewvc/llvm-project?rev=209723&view=rev and doesn't
look like it has any flag control.

This code has Undefined Behavior (by binding a dereferenced null
pointer to a reference).

- David




More information about the cfe-dev mailing list