Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-11623

Compound literals fail to implicitly instantiate template types

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Not Prioritized Not Prioritized

      The compiler sometimes rejects compound literals when the intended type of the literal is a template type. Note that compound literals are a C99 feature, not a C++ feature, but the parser does support compound literals in C++ in relaxed mode, so the parser should accept this test case. It looks like the parser rejects template types when they aren't implicitly instantiated at an earlier point in the code.

      template< int n > struct Foo { };
      
      // Uncomment this line and it builds clean
      // Foo<0> blah;  // implicitly instantiates Foo<0>
      
      void init_foo( Foo<0> *p ) {
          *p = (Foo<0>){ };
          // error: a compound literal of type "Foo<0>" is not allowed
      }
      

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: