On 05/08/2012 04:10 AM, Jason Merrill wrote:
How do we even get to calling cp_truthvalue_conversion?
ocp_convert wants to do that, around line 750... And I have a brand new proposal ;)

The patchlet below (which passes testing) leads to very consistent error messages for the testcase in the PR, and:

void foo();

void bar(int a, int b)
{
if (foo())
;
}

and

void foo();

void bar(int a, int b)
{
if (foo() && a < b)
;
}

exactly the same actually. But maybe we want to differentiate somehow what we emit for lambdas, but I don't think we want the status quo for %qE for a lambda here, because it would be:

error: could not convert ‘b.main()::<lambda()>()’ from ‘void’ to ‘bool’

What do you think?

Thanks!
Paolo.

///////////////////////////
Index: testsuite/g++.dg/cpp0x/lambda/lambda-err2.C
===================================================================
--- testsuite/g++.dg/cpp0x/lambda/lambda-err2.C (revision 0)
+++ testsuite/g++.dg/cpp0x/lambda/lambda-err2.C (revision 0)
@@ -0,0 +1,12 @@
+// PR c++/53158
+// { dg-do compile { target c++11 } }
+
+int main()
+{
+  auto a = []() { return true; };
+  auto b = []() { return a(); };  // { dg-error "'a' is not captured" }
+  int c, d;
+  while (b() && c < d) // { dg-error "could not convert 'b\\(\\)' from 'void' 
to 'bool'" }
+    {
+    }
+}
Index: cp/error.c
===================================================================
--- cp/error.c  (revision 187249)
+++ cp/error.c  (working copy)
@@ -1897,6 +1897,13 @@ dump_expr (tree t, int flags)
            if (TREE_CODE (ob) == ADDR_EXPR)
              {
                dump_expr (TREE_OPERAND (ob, 0), flags | TFF_EXPR_IN_PARENS);
+               /* Handle lambdas specially.  */
+               if (TREE_CODE (fn) == FUNCTION_DECL
+                   && DECL_NAME (fn) && LAMBDA_FUNCTION_P (fn))
+                 {
+                   dump_call_expr_args (t, flags, true);
+                   return;
+                 }
                pp_cxx_dot (cxx_pp);
              }
            else if (TREE_CODE (ob) != PARM_DECL
Index: cp/cvt.c
===================================================================
--- cp/cvt.c    (revision 187249)
+++ cp/cvt.c    (working copy)
@@ -743,6 +743,12 @@ ocp_convert (tree type, tree expr, int convtype, i
        }
       if (code == BOOLEAN_TYPE)
        {
+         if (TREE_CODE (intype) == VOID_TYPE)
+           {
+             error ("could not convert %qE from %<void%> to %<bool%>", expr);
+             return error_mark_node;
+           }
+
          /* We can't implicitly convert a scoped enum to bool, so convert
             to the underlying type first.  */
          if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC))

Reply via email to