After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 342911 - Only last lambda expression from list separated by comma is executed
Only last lambda expression from list separated by comma is executed
Status: RESOLVED FIXED
Product: libsigc++
Classification: Bindings
Component: signals
2.0.x
Other All
: Normal normal
: ---
Assigned To: libsigc++ maintainer(s)
libsigc++ maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2006-05-25 12:32 UTC by Andris Pavenis
Modified: 2013-03-04 15:05 UTC
See Also:
GNOME target: ---
GNOME version: 2.11/2.12


Attachments
Test example for a bug (655 bytes, text/plain)
2006-05-25 12:37 UTC, Andris Pavenis
  Details
Updated test example (compares also result of comma operator) (727 bytes, text/plain)
2006-05-25 14:36 UTC, Andris Pavenis
  Details
Patch that fixes the problem for me (2.04 KB, patch)
2006-05-25 14:44 UTC, Andris Pavenis
none Details | Review
patch: Fix comma operator in lambda expressions. (4.94 KB, patch)
2012-09-20 16:51 UTC, Kjell Ahlstedt
none Details | Review

Description Andris Pavenis 2006-05-25 12:32:17 UTC
Please describe the problem:
I tried to connect signal<void, int, int> following lambda expression:

hide_return((var(a)=_1, var(b)=_2))

where a and b are integer variables. Only the second assignment is performed
when signal is emmitted.

Steps to reproduce:
1. 
2. 
3. 


Actual results:
The value of a remains unchanged and a new value is assigned to b

Expected results:
The new values should be asigned to both variables a and b

Does this happen every time?
Yes

Other information:
Comment 1 Andris Pavenis 2006-05-25 12:37:57 UTC
Created attachment 66183 [details]
Test example for a bug

Command line for compiling the example:

g++ `pkg-config --cflags sigc++-2.0` bug_20060524.cpp `pkg-config --libs sigc++-2.0` -lboost_signals -o bug_20060524

Boost (http://www.boost.org) is used for comparisson. With it I'm getting the expected behaviour.
Comment 2 Andris Pavenis 2006-05-25 14:36:55 UTC
Created attachment 66193 [details]
Updated test example (compares also result of comma operator)
Comment 3 Andris Pavenis 2006-05-25 14:44:47 UTC
Created attachment 66194 [details] [review]
Patch that fixes the problem for me

Unfortunatelly I cannot use M4 macro LAMBDA_OPERATOR as I'm getting about left side of comma operator having no effect. So I had to add cast to void. Perhaps we don't need to support comma operator when one side is not a lambda type.

Test environment: Fedora Core 5, gcc version 4.1.0 20060304 (Red Hat 4.1.0-3).
Comment 4 Murray Cumming 2007-07-28 12:24:48 UTC
I don't really feel qualified to review this because I don't use this libsigc++ feature.

But I don't like that we have ignored this patch.
Comment 5 André Klapper 2011-09-22 09:01:59 UTC
[Resetting QA Contact and Assignee to default - see bug 659799 for more info]
Comment 6 Andris Pavenis 2011-09-23 09:58:37 UTC
Verified that

1) bug is still there in libsigc++-2.2.10 (tested in Fedora 15 x86_64)

2) attached patch still applies without problems and also FIXES the bug
   for that version (sources from ftp.gnome.org, not Fedora distribution)
Comment 7 Murray Cumming 2012-01-30 10:26:02 UTC
Review of attachment 66194 [details] [review]:

::: sigc++/adaptors/lambda/macros/operator.h.m4
@@ +292,3 @@
 struct static_ {};
 struct dynamic_ {};
+struct comma {};

Should this be comma_ rather than comma?
Comment 8 Murray Cumming 2012-01-30 10:27:51 UTC
I don't think I've ever seen comma operator overloading before. Do we do this already in libsigc++?

I would also like a test case to be integrated with the build (during make check) like the existing checks.
Comment 9 Andris Pavenis 2012-01-31 18:19:03 UTC
It would be nice to add testcase.

What could be best place for it?
I wanted to put it into test_lambda.cc, but it's not
built by 'make check'

Maybe it should be enabled and excluded only for targets
where it does not build (either by build configuration or using C++
preprocessor defines specific for target)
Comment 10 Murray Cumming 2012-03-01 13:33:59 UTC
(In reply to comment #9)
> Maybe it should be enabled and excluded only for targets
> where it does not build

That sounds good.

> (either by build configuration or using C++
> preprocessor defines specific for target)

A configure test would be best.
Comment 11 Kjell Ahlstedt 2012-03-19 08:11:54 UTC
(In reply to comment #9)
> I wanted to put it into test_lambda.cc, but it's not
> built by 'make check'

See bug 669128.
Comment 12 Murray Cumming 2012-09-17 20:18:21 UTC
Andris, will you update your patch?
Comment 13 Andris Pavenis 2012-09-18 04:12:20 UTC
As far as I have tested earlier with the latest version I see on ftp.gnome.org (2.2.10) the old patch is still OK (comment 6). Also updated test example can be used with only small modifications in testsuite:
- remove boost part
- check result of assignments from lambda expression

Rebuilt this test example on Fedora 17 x86_64 and got:

[andris@ap sigc++]$ g++ -O2 $(pkg-config --cflags sigc++-2.0) -Wall -Wextra comma_test.cpp $(pkg-config --libs sigc++-2.0) -lboost_signals-mt
[andris@ap sigc++]$ ./a.out
BOOST: a=2 b=3 c=3
libsigc++: a=-1 b=3 c=3
[andris@ap sigc++]$ pkg-config --modversion sigc++-2.0
2.2.10

I have not tested patch with the current development sources though
Comment 14 Kjell Ahlstedt 2012-09-20 16:51:56 UTC
Created attachment 224847 [details] [review]
patch: Fix comma operator in lambda expressions.

Here's a patch that includes both the additions to operator.h.m4 (without the
preprocessor constant __SIGC_LAMBDA_COMMA_OPERATOR_NAME) and a test case.
The test case differs from the one in comment 2, because I wanted it to be more
similar to most other tests in test_lambda.cc (without sigc::slot and
sigc::signal).

(In reply to comment #7)
> Should this be comma_ rather than comma?

I don't think so. If you look at the whole list of empty structs in
operator.h.m4, you will see that most of them have names that do not end with
an underscore. Most of the underscores are added because the names would
otherwise be equal to a C++ keyword. (At least that's what I think is the main
reason.)
Comment 15 Andris Pavenis 2012-09-23 08:25:17 UTC
Looks OK for me.

I myself would prefer using of cppunit or some some similar library for testing instead of having to review test results though
Comment 16 Murray Cumming 2012-09-23 11:41:55 UTC
OK. Feel free to push this.
Comment 17 Kjell Ahlstedt 2012-09-23 17:22:38 UTC
I've pushed the patch in comment 14.

(In reply to comment #15)
> I myself would prefer using of cppunit or some some similar library for
> testing instead of having to review test results though

Most of the test cases in libsigc++2/tests are not well suited for their job.
They produce output that someone must check manually. They should be quiet
when everything is OK and report the result with an exit status.

As it is, 'make check' will only detect compile-time errors, but not run-time
errors, because usually no one will check the output (I suspect).

I have thought of fixing at least some of the test cases. Perhaps I will do it
in the future. (No promise!) That's beyond the scope of this bug.
Comment 18 Kjell Ahlstedt 2013-03-04 15:05:40 UTC
(In reply to comment #17)
> I have thought of fixing at least some of the test cases. Perhaps I will do
> it in the future. (No promise!) That's beyond the scope of this bug.

Done some time ago. See bug 684956.