[arm-gnu] Fwd: Another Template related bug [compile time assertions with templates] - not sure whether this is a GCC bug
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[arm-gnu] Fwd: Another Template related bug [compile time assertions with templates] - not sure whether this is a GCC bug



Hi,

seems we may have come across a possible GCC bug. Not 100% sure though: the issue has to do with our definition of compile time assertions, which is defined as follows - using the well-formedness of a function definition to do the assertion.

    #define __ASSERT_COMPILE(x)  void __foo(int __check[x?1:-1])

Now it seems that in combination with templates, using the assert macro sometimes falls over, with the following error

  H:/epoc32/include/platform/elements/nm_signatures.h:505:
  error: default template arguments may not be used in function templates

I attached an e-mail snippet, which shows when the we get the error and when not

  #*define*  __Align8  <http://developer.symbian.org/xref/epl/s?refs=__Align8&project=/MCL>(s) ((((s)+__Size8  <http://developer.symbian.org/xref/oss/xref/MCL/sf/os/kernelhwsrv/kernel/eka/include/e32des8.h#__Size8>-1)/__Size8  <http://developer.symbian.org/xref/oss/xref/MCL/sf/os/kernelhwsrv/kernel/eka/include/e32des8.h#__Size8>)*__Size8  <http://developer.symbian.org/xref/oss/xref/MCL/sf/os/kernelhwsrv/kernel/eka/include/e32des8.h#__Size8>)

The solution we propose is to use the macro outside the inlined function, which appears to work.

Best Regards
Lars

-------- Original Message --------
Subject: 	Re: Another Template related bug...
From: 	Daniel Rubio <danielr@xxxxxxxxxxx>


Hi Remek,

I have spent some time on this at the weekend.

1- The the assert macro expands as a function within member function of the templated class, and that is interpreted as a templated function, but only in THAT particular class template (see below, I tried to reproduce the problem with simpler code unsuccessfully):

If you put the assert outside of the member function declaration/implementation it serves the same purpose, i.e. the class instantiation will fail at compile time if the condition is false, and GCCE can build the component. Please let me know if you think this is ok and then I will submit it as a fix

Template <class TSIGNATURE, TInt PAYLOADATTRIBOFFSET, class TATTRIBUTECREATIONPOLICY, TInt PAYLOADBUFFERMAXLEN = TSignalBase::KMaxInlineMessageSize> class TSignatureWithPolymorphicPayloadMetaType : public TSignatureWithPolymorphicPayloadMetaTypeBase
{
public:
*_ASSERT_COMPILE(**PAYLOADATTRIBOFFSET == __Align8(PAYLOADATTRIBOFFSET))**; //This compiles*

    inline static MMetaType* NewL(const TAny* aMem, const TAny* aData)
        {
// For some reason this assertion does not compile under x86gcc which complains // that a default template argument has been specified for a templated member // function. There is no such function so this is probably a parser bug.
        #if !defined(__GCCXML__) && !defined(__X86GCC__)
*//__ASSERT_COMPILE(**PAYLOADATTRIBOFFSET == __Align8(PAYLOADATTRIBOFFSET))**; //This DOES NOT compile*
*
*        #endif
return ::new ((TUint8*)aMem) TSignatureWithPolymorphicPayloadMetaType(aData);
        }


2 - I tried to write "similar" code (clearer) to test but I could not manage to reproduce the error, so I think it may be a parser error since in the original code in which somehow it assumes that the macro is a template fucntion when it is expanded. The main difference between my code and the original code is that I am using a simple class not derived from a base class:

#define __ASSERT_COMPILE(x)  void __foo(int __check[x?1:-1])
template <class T, int PAYLOAD>
class list {
    public:
    typedef unsigned int myType;
    inline static myType setSize (unsigned int x, unsigned int y, T myVar)
    {
    __ASSERT_COMPILE(PAYLOAD);
    }

    };
Unsurprisingly, this code compiles without any errors (if PAYLOAD>0).

Let me know.

Daniel.






Some facts about Symbian that we are legally obliged to tell you: Symbian Foundation Limited is a Company Limited by Guarantee and not having Share Capital
We're registered in England and Wales - Companies House knows us by the number 6683783
Our address is 1 Boundary Row, Southwark, London SE1 8HP.

begin:vcard
fn:Lars Kurth
n:Kurth;Lars
org:Symbian Foundation;Technology & Delivery
adr:;;1 Boundary Row;London;;SE1 8HP;UK
email;internet:larsk@xxxxxxxxxxx
title:Contributor Community
tel;cell:+44 7788 576 889
url:developer.symbian.org
version:2.1
end:vcard