Skip to content
Snippets Groups Projects
  • Jakub Jelinek's avatar
    2499540e
    c++: Reject pack expansion of assume attribute [PR109756] · 2499540e
    Jakub Jelinek authored
    http://eel.is/c++draft/dcl.attr#grammar-4 says
    "In an attribute-list, an ellipsis may appear only if that attribute's
    specification permits it."
    and doesn't explicitly permit it on any standard attribute.
    The https://wg21.link/p1774r8 paper which introduced assume attribute says
    "We could therefore hypothetically permit the assume attribute to directly
    support pack expansion:
    template <int... args>
    void f() {
    [[assume(args >= 0)...]];
    }
    However, we do not propose this. It would require substantial additional work
    for a very rare use case. Note that this can instead be expressed with a fold
    expression, which is equivalent to the above and works out of the box without
    any extra effort:
    template <int... args>
    void f() {
    [[assume(((args >= 0) && ...))]];
    }
    ", but as the testcase shows, GCC 13+ ICEs on assume attribute followed by
    ... if it contains packs.
    The following patch rejects those instead of ICE and for C++17 or later
    suggests using fold expressions instead (it doesn't make sense to suggest
    it for C++14 and earlier when we'd error on the fold expressions).
    
    2023-05-09  Jakub Jelinek  <jakub@redhat.com>
    
    	PR c++/109756
    	* cp-gimplify.cc (process_stmt_assume_attribute): Diagnose pack
    	expansion of assume attribute.
    
    	* g++.dg/cpp23/attr-assume11.C: New test.
    2499540e
    History
    c++: Reject pack expansion of assume attribute [PR109756]
    Jakub Jelinek authored
    http://eel.is/c++draft/dcl.attr#grammar-4 says
    "In an attribute-list, an ellipsis may appear only if that attribute's
    specification permits it."
    and doesn't explicitly permit it on any standard attribute.
    The https://wg21.link/p1774r8 paper which introduced assume attribute says
    "We could therefore hypothetically permit the assume attribute to directly
    support pack expansion:
    template <int... args>
    void f() {
    [[assume(args >= 0)...]];
    }
    However, we do not propose this. It would require substantial additional work
    for a very rare use case. Note that this can instead be expressed with a fold
    expression, which is equivalent to the above and works out of the box without
    any extra effort:
    template <int... args>
    void f() {
    [[assume(((args >= 0) && ...))]];
    }
    ", but as the testcase shows, GCC 13+ ICEs on assume attribute followed by
    ... if it contains packs.
    The following patch rejects those instead of ICE and for C++17 or later
    suggests using fold expressions instead (it doesn't make sense to suggest
    it for C++14 and earlier when we'd error on the fold expressions).
    
    2023-05-09  Jakub Jelinek  <jakub@redhat.com>
    
    	PR c++/109756
    	* cp-gimplify.cc (process_stmt_assume_attribute): Diagnose pack
    	expansion of assume attribute.
    
    	* g++.dg/cpp23/attr-assume11.C: New test.