Bug 62036 - Braced-init-list issuing -Wsequence-point warning
Summary: Braced-init-list issuing -Wsequence-point warning
Status: RESOLVED DUPLICATE of bug 51253
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-06 14:08 UTC by Cameron
Modified: 2014-08-06 18:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cameron 2014-08-06 14:08:28 UTC
#include <algorithm>
#include <iostream>
#include <iterator>
#include <thread>

int main() {
    int arr[10];
    std::iota(std::begin(arr), std::end(arr), 1);
    using itr_t = decltype(std::begin(arr));

    // the function that will display each element
    auto f = [] (itr_t first, itr_t last) {while (first != last) std::cout<<*(first++)<<' ';};

    // we have 3 threads so we need to figure out the ranges for each thread to show
    int increment = std::distance(std::begin(arr), std::end(arr)) / 3;
    auto first    = std::begin(arr);
    auto to       = first + increment;
    auto last     = std::end(arr);
    std::thread threads[3] = {
        std::thread{f, first, to},
        std::thread{f, (first = to), (to += increment)},
        std::thread{f, (first = to), last} // go to last here to account for odd array sizes
    };
    for (auto&& t : threads) t.join();
}


I'm getting the sequence point warning with this piece of code and when I execute it the thread at threads[1] prints nothing whatsoever. This should be well defined according to the standard (I'm using sec. 8.5.4.4 as reference). The fact that gcc even issues the -Wsequence-point warning is indicative that the standard isn't being followed.
Comment 1 Jonathan Wakely 2014-08-06 15:06:44 UTC
As pointed out at http://stackoverflow.com/questions/25115189/optimization-bug-regarding-gcc-stdthread#comment39095137_25115189 (where you apparently copied this code from) there's a known bug which is fixed in GCC 4.9, see PR51253
Comment 2 Cameron 2014-08-06 15:12:06 UTC
Welp looks like my friend got to it before I did. My bad. Carry on and good work!
Comment 3 Cameron 2014-08-06 18:35:58 UTC
duplicate of bug 51253

*** This bug has been marked as a duplicate of bug 51253 ***