No compiler diagnostic when identifier in a simple-capture appears as the declarator-id of a parameter

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
10
down vote

favorite
2












The section on lambda captures ([expr.prim.lambda.capture]/5) states that




If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.




Consider the follow example:



#include <iostream>

int main ()

auto foo = 1234;
auto bar = [foo](int foo) std::cout << foo << 'n'; ;
bar(4321);



GCC 8.2.0 has no diagnostic for this. Neither does Clang 7.0.0.



Should there be a diagnostic (error/warning) from these compilers (as mentioned
in the reference) along the lines of:



// parameter and simple-capture have the same name


Godbolt Demo here










share|improve this question























  • actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
    – user463035818
    1 hour ago






  • 5




    @user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
    – StoryTeller
    1 hour ago






  • 2




    @StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
    – user463035818
    1 hour ago






  • 1




    @user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
    – StoryTeller
    1 hour ago














up vote
10
down vote

favorite
2












The section on lambda captures ([expr.prim.lambda.capture]/5) states that




If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.




Consider the follow example:



#include <iostream>

int main ()

auto foo = 1234;
auto bar = [foo](int foo) std::cout << foo << 'n'; ;
bar(4321);



GCC 8.2.0 has no diagnostic for this. Neither does Clang 7.0.0.



Should there be a diagnostic (error/warning) from these compilers (as mentioned
in the reference) along the lines of:



// parameter and simple-capture have the same name


Godbolt Demo here










share|improve this question























  • actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
    – user463035818
    1 hour ago






  • 5




    @user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
    – StoryTeller
    1 hour ago






  • 2




    @StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
    – user463035818
    1 hour ago






  • 1




    @user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
    – StoryTeller
    1 hour ago












up vote
10
down vote

favorite
2









up vote
10
down vote

favorite
2






2





The section on lambda captures ([expr.prim.lambda.capture]/5) states that




If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.




Consider the follow example:



#include <iostream>

int main ()

auto foo = 1234;
auto bar = [foo](int foo) std::cout << foo << 'n'; ;
bar(4321);



GCC 8.2.0 has no diagnostic for this. Neither does Clang 7.0.0.



Should there be a diagnostic (error/warning) from these compilers (as mentioned
in the reference) along the lines of:



// parameter and simple-capture have the same name


Godbolt Demo here










share|improve this question















The section on lambda captures ([expr.prim.lambda.capture]/5) states that




If an identifier in a simple-capture appears as the declarator-id of a parameter of the lambda-declarator's parameter-declaration-clause, the program is ill-formed.




Consider the follow example:



#include <iostream>

int main ()

auto foo = 1234;
auto bar = [foo](int foo) std::cout << foo << 'n'; ;
bar(4321);



GCC 8.2.0 has no diagnostic for this. Neither does Clang 7.0.0.



Should there be a diagnostic (error/warning) from these compilers (as mentioned
in the reference) along the lines of:



// parameter and simple-capture have the same name


Godbolt Demo here







c++ language-lawyer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Some programmer dude

287k24234395




287k24234395










asked 1 hour ago









P.W

5,6391331




5,6391331











  • actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
    – user463035818
    1 hour ago






  • 5




    @user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
    – StoryTeller
    1 hour ago






  • 2




    @StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
    – user463035818
    1 hour ago






  • 1




    @user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
    – StoryTeller
    1 hour ago
















  • actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
    – user463035818
    1 hour ago






  • 5




    @user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
    – StoryTeller
    1 hour ago






  • 2




    @StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
    – user463035818
    1 hour ago






  • 1




    @user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
    – StoryTeller
    1 hour ago















actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
– user463035818
1 hour ago




actually I dont really see the problem with the example. Looks like shadowing that in other places is not an error, though from the paragraph you quote i'd also expect this to be an error
– user463035818
1 hour ago




5




5




@user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
– StoryTeller
1 hour ago




@user463035818 - A misconception. Shadowing is already an error under certain circumstances. For instance, you can't shadow a function parameter in the functions immediate block.
– StoryTeller
1 hour ago




2




2




@StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
– user463035818
1 hour ago




@StoryTeller well really a misconception then. Thanks for pointing it out. I always thought shadowing is fine everywhere....
– user463035818
1 hour ago




1




1




@user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
– StoryTeller
1 hour ago




@user463035818 - That's probably because you, like any other sane person, won't feel the urge to shadow something they only just defined as a function parameter :) It's only really those pathological cases that the standard flags as ill-formed.
– StoryTeller
1 hour ago












1 Answer
1






active

oldest

votes

















up vote
13
down vote













That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.



It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.






share|improve this answer




















    Your Answer





    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52947934%2fno-compiler-diagnostic-when-identifier-in-a-simple-capture-appears-as-the-declar%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    13
    down vote













    That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.



    It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.






    share|improve this answer
























      up vote
      13
      down vote













      That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.



      It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.






      share|improve this answer






















        up vote
        13
        down vote










        up vote
        13
        down vote









        That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.



        It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.






        share|improve this answer












        That wording was added to C++17 to resolve CWG Defect 2211. It didn't exist in C++14, and it would seem that Clang and GCC haven't caught up to this change up to the versions you are checking.



        It's worth noting that the GCC trunk does indeed diagnose that program as ill-formed under C++17.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 1 hour ago









        StoryTeller

        86.3k12173241




        86.3k12173241



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52947934%2fno-compiler-diagnostic-when-identifier-in-a-simple-capture-appears-as-the-declar%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery