IBM Support

LI77859: Template type argument not evaluated correctly

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as program error.

Error description

  • Compile errors and incorrect runtime behaviour is seen when
    specialized template code uses template dependent expressions
    as template type arugments.  The compiler may evaluate the
    expression incorrectly, leading to a compile error, or
    unexpected runtime behaviour.
    
    An example may be using a boolean expression as a template
    argument:
    
    ------------------
    template <typename TYPE>
    struct mystruct< TYPE , typename
    enable_if<not(not(always_true<TYPE>::value))>::type >
    ------------------
    
    , which may evaluate the boolean 'not' operations incorrectly,
    giving incorrect behaviour.
    
    A more complex compile-error example is given below:
    
    
    ===== TESTCASE:
    $cat sfinae.cpp
    
    #include <iostream>
    
    template <bool Condition, typename T = void>
    struct enable_if;
    
    template <typename T>
    struct enable_if<true,T> { typedef T type; };
    
    template <typename U, typename V>
    struct is_same { static const bool value = false; };
    
    template <typename U>
    struct is_same<U,U> { static const bool value = true; };
    
    
    template <typename N, typename M, typename Enable = void>
    struct Foo;
    
    template <typename N, typename M>
    struct Foo<N,M, typename enable_if< is_same<N,M>::value >::type>
    {
      static void print()
      {
        std::cout << "Hello" << std::endl;
      }
    };
    
    template <typename N, typename M>
    struct Foo <N,M, typename enable_if< (!is_same<N,M>::value)
    >::type>
    {
      static void print()
      {
        std::cout << "World" << std::endl;
      }
    };
    
    int main()
    {
      Foo<int,int>::print();
      Foo<int,unsigned>::print();
    
      return 0;
    }
    
    ===== ACTUAL OUTPUT:
    xlC -c sfinae.cpp
    "sfinae.cpp", line 40.3: 1540-0130 (S) "Foo<int,unsigned
    int,void>::print" is not declared.
    
    ===== EXPECTED OUTPUT:
    Compiles clean.
    

Local fix

  • N/A
    

Problem summary

  • PROBLEM DESCRIPTION:
    Template testcase is failing on XL C++ compiler due to argument
    deduction error.
    
    USERS AFFECTED:
    Users with template type dependent arguments with boolean
    expression.
    

Problem conclusion

  • Problem has been fixed, and template arguments are now deducted
    correctly.
    

Temporary fix

Comments

APAR Information

  • APAR number

    LI77859

  • Reported component name

    XL C/C++ FOR BG

  • Reported component ID

    5799AG100

  • Reported release

    C10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2014-02-13

  • Closed date

    2014-08-14

  • Last modified date

    2014-08-14

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

    IV61653 IV65313 LI78259

Fix information

  • Fixed component name

    XL C/C++ FOR BG

  • Fixed component ID

    5799AG100

Applicable component levels

  • RC10 PSY

       UP



Document information

More support for: XL C/C++ for Blue Gene/Q
Compiler

Software version: 12.1

Reference #: LI77859

Modified date: 14 August 2014