https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83050
Bug ID: 83050 Summary: Please provide shortcircuit attribute for || and && operators Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bugzi...@poradnik-webmastera.com Target Milestone: --- Built-int || and && operators are shortcircuiting, i.e. they may skip evaluation of 2nd argument in some cases. However overloaded || and && operators do not work in this way, they always evaluate both arguments. Sometimes it would be handy if they also could support shortcircuiting. I propose to add new shortcircuit attribute, which could be attached to overloaded operator: __attribute__((shortcircuit)) T1 operator||(T2 a, T3 b); __attribute__((shortcircuit)) T1 operator&&(T2 a, T3 b); With such attribute gcc would generate a bit different code, e.g. something like this: || operator: if ((bool)a) (T1)a; else operator||(a, b); && operator: if ((bool)a) operator&&(a, b); else (T1)a; This new attribute potentially could also be attached to other overloaded operators (+, -, ...), but I have doubts if gcc should accept this - probably it would be better to prohibit this.