Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expression template - decorated name length exceeded

I get a "Decorated name length exceeded" warning from my code I've looked at the SO answers to similar questions. *N.B. I know how to turn this off (pragma), I also know that it is a warning I can "ignore" and that unix based compilers may not emit it :P *

There is a practical element to this question , If I get errors I do have to wade through some pretty horrendous text and templates. These errors are mostly due to typos currently, but if I had anything subtle it would be a nightmare to actually find what the issue is.

My code compiles and works, but as I said above I get a warning. I have a "relatively" small expression

...
auto expression = (l,aComma,w,aComma,x,aComma,y,aComma,z);
std::cout << expression;

that I generate from a comma operator I have defined for my expression template (I can post if required but trying to keep this minimal - Pretty standard stuff copied):

//
//Expression 
//
template < class E >
struct Expr 
{
    E expr_;
    Expr (E e) : expr_ (e) {}
    std::ostream& print(std::ostream& out) { return expr_.print(out); }
};

template < class L, class H, class OP >
struct BinExpr 
{
    L l_;
    H h_;
    BinExpr (L l, H h) : l_ (l), h_ (h) {}
    std::ostream& print(std::ostream& out) { l_.print(out) ; return h_.print(out); }
};

template< class A, class B >
Expr< BinExpr< Expr<A>, Expr<B>, Print<Expr<A>,Expr<B> > > > 
operator , ( Expr<A> a, Expr<B> b )
{
    typedef BinExpr < Expr<A>, Expr<B>, Print<Expr<A>,Expr<B> > > ExprT;
    return Expr<ExprT>(ExprT(a,b));
}

The Microsoft page talks about refactoring to avoid this warning. MS wraps each level in a plain struct which then contains a templated element member. The problem with that is that the whole point in writing the expression template is to use implicit construction to create the tree of objects required, avoiding having to define exactly what I will be creating before hand. So...

  • The Question I want to ask is whether I can somehow typedef the length down without losing function and flexibility?

  • Or, can I somehow use the Microsoft suggestion to wrap parts of the structures, again , without losing function and flexibility? I can do that for the types I am going to use in the Expr objects as I will be setting them up before "listing" them in between the commas. But the length will grow as I add more items and so it will probably hit this limit again. I'll also be adding more complexity to this as I add new function. These will be similarly created and so most likely generate more headaches...

  • Are there any features of C++11 that I could use to help? I tried a trailing return type but the internal typedef was not in effect (and I'm not sure it would have helped).


like image 413
Caribou Avatar asked Nov 09 '12 15:11

Caribou


1 Answers

Whenever I have encountered this warning and looked in to refactoring the code so that the warning is not emitted, I found in every case that refactoring was impossible. If I didn't need all those template parameters, I wouldn't have had them there in the first place.

The MS page also says:

The correctness of the program, however, is unaffected by the truncated name.

Based on this fact, my SOP is to #pragma the warning away:

#pragma warning( disable: 4503 )

This solution is a bit like an atomic bomb, I admit. However this is the only instance in which I will actually ignore a compiler warning on any level, and I believe it can be safely ignored.

like image 190
John Dibling Avatar answered Sep 29 '22 04:09

John Dibling