Hi again,
On 05/08/2012 03:00 PM, Jason Merrill wrote:
On 05/07/2012 11:28 PM, Paolo Carlini wrote:
error: could not convert ‘b.main()::<lambda()>()’ from ‘void’ to ‘bool’
It wouldn't say "operator()"?
I think I'd leave that alone; it is somewhat more informative (about
what b() expands to) and we're moving toward replacing %qE with caret
anyway.
The patch to ocp_convert is OK.
As you may have noticed, the patchlet is still unapplied (I'm attaching
below what I have tested and ready to get in per your approval).
Is unapplied because I was really nervous due to the wrong location
(thus caret) of the error call, at the end of the whole condition. Now,
I'm wondering, shall we consistently use error_at (location_of (expr),
... for the error messages produced by the *convert* functions? The
below quick fix makes me *much* more happy, the caret points to the
closed round brace of the b() call. Can I trust all the exprs to come
with an embedded location *at least* as accurate as input_location,
normally better? In case I can do a pass through all of cvt.c etc and
repost a largish patch...
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" }
+ {
+ }
+}
Index: cp/cvt.c
===================================================================
--- cp/cvt.c (revision 187280)
+++ 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))
Index: cvt.c
===================================================================
--- cvt.c (revision 187290)
+++ cvt.c (working copy)
@@ -743,6 +743,14 @@ ocp_convert (tree type, tree expr, int convtype, i
}
if (code == BOOLEAN_TYPE)
{
+ if (TREE_CODE (intype) == VOID_TYPE)
+ {
+ error_at (location_of (expr),
+ "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))