Thread: forward declaration error reported by llvm-gcc-4.2

  1. #1
    Registered User
    Join Date
    Jun 2016
    Posts
    2

    Question forward declaration error reported by llvm-gcc-4.2

    When I use llvm-gcc-4.2 within Xcode4.6.3 to compile 'x265' sources, it reported a strange error: ./source/encoder/reference.h:38:error: forward declaration of 'class x265::MotionReference'.However, the class declaration of x265::MotionReference is complete in reference.h:
    Code:
    #ifndef X265_REFERENCE_H
    #define X265_REFERENCE_H
    
    #include"primitives.h"
    #include"picyuv.h"
    #include"lowres.h"
    #include"mv.h"
    
    namespace X265_NS {
    // private x265 namespace
    
    structWeightParam;
    
    classMotionReference:publicReferencePlanes
    {
    public:
    
        MotionReference();
        ~MotionReference();
        int  init(PicYuv*,WeightParam* wp,const x265_param& p);
        void applyWeight(int rows,int numRows);
    
        pixel*  weightBuffer[3];
        int     numInterpPlanes;
        int     numWeightedRows;
    
    protected:
    
        MotionReference&operator=(constMotionReference&);
    };
    }
    

    and it's parent class is defined in header file 'lowres.h':
    Code:
    
    #ifndef X265_LOWRES_H
    #define X265_LOWRES_H
    
    #include"primitives.h"
    #include"common.h"
    #include"picyuv.h"
    #include"mv.h"
    
    namespace X265_NS {
    // private namespace
    
    structReferencePlanes
    {
        ReferencePlanes(){ memset(this,0,sizeof(ReferencePlanes));}
    
        pixel*   fpelPlane[3];
        pixel*   lowresPlane[4];
        PicYuv*  reconPic;
    
        bool     isWeighted;
        bool     isLowres;
    
        intptr_t lumaStride;
        intptr_t chromaStride;
    
        struct{
            int      weight;
            int      offset;
            int      shift;
            int      round;
        } w[3];
    
        pixel* getLumaAddr(uint32_t ctuAddr,uint32_t absPartIdx){return fpelPlane[0]+ reconPic->m_cuOffsetY[ctuAddr]+ reconPic->m_buOffsetY[absPartIdx];}
        pixel* getCbAddr(uint32_t ctuAddr,uint32_t absPartIdx){return fpelPlane[1]+ reconPic->m_cuOffsetC[ctuAddr]+ reconPic->m_buOffsetC[absPartIdx];}
        pixel* getCrAddr(uint32_t ctuAddr,uint32_t absPartIdx){return fpelPlane[2]+ reconPic->m_cuOffsetC[ctuAddr]+ reconPic->m_buOffsetC[absPartIdx];}
    
        /* lowres motion compensation, you must provide a buffer and stride for QPEL averaged pixels
         * in case QPEL is required.  Else it returns a pointer to the HPEL pixels */
        inline pixel *lowresMC(intptr_t blockOffset,const MV& qmv, pixel *buf,intptr_t& outstride)
        {
            if((qmv.x | qmv.y)&1)
            {
                int hpelA =(qmv.y &2)|((qmv.x &2)>>1);
                pixel *frefA = lowresPlane[hpelA]+ blockOffset +(qmv.x >>2)+(qmv.y >>2)* lumaStride;
                int qmvx = qmv.x +(qmv.x &1);
                int qmvy = qmv.y +(qmv.y &1);
                int hpelB =(qmvy &2)|((qmvx &2)>>1);
                pixel *frefB = lowresPlane[hpelB]+ blockOffset +(qmvx >>2)+(qmvy >>2)* lumaStride;
                primitives.pu[LUMA_8x8].pixelavg_pp(buf, outstride, frefA, lumaStride, frefB, lumaStride,32);
                return buf;
            }
            else
            {
                outstride = lumaStride;
                int hpel =(qmv.y &2)|((qmv.x &2)>>1);
                return lowresPlane[hpel]+ blockOffset +(qmv.x >>2)+(qmv.y >>2)* lumaStride;
            }
        }
    
        inlineint lowresQPelCost(pixel *fenc,intptr_t blockOffset,const MV& qmv,pixelcmp_t comp)
        {
            if((qmv.x | qmv.y)&1)
            {
                ALIGN_VAR_16(pixel, subpelbuf[8*8]);
                int hpelA =(qmv.y &2)|((qmv.x &2)>>1);
                pixel *frefA = lowresPlane[hpelA]+ blockOffset +(qmv.x >>2)+(qmv.y >>2)* lumaStride;
                int qmvx = qmv.x +(qmv.x &1);
                int qmvy = qmv.y +(qmv.y &1);
                int hpelB =(qmvy &2)|((qmvx &2)>>1);
                pixel *frefB = lowresPlane[hpelB]+ blockOffset +(qmvx >>2)+(qmvy >>2)* lumaStride;
                primitives.pu[LUMA_8x8].pixelavg_pp(subpelbuf,8, frefA, lumaStride, frefB, lumaStride,32);
                return comp(fenc, FENC_STRIDE, subpelbuf,8);
            }
            else
            {
                int hpel =(qmv.y &2)|((qmv.x &2)>>1);
                pixel *fref = lowresPlane[hpel]+ blockOffset +(qmv.x >>2)+(qmv.y >>2)* lumaStride;
                return comp(fenc, FENC_STRIDE, fref, lumaStride);
            }
        }
    };
    
    /* lowres buffers, sizes and strides */
    structLowres:publicReferencePlanes
    {
        pixel *buffer[4];
    
        int    frameNum;// Presentation frame number
        int    sliceType;// Slice type decided by lookahead
        int    width;// width of lowres frame in pixels
        int    lines;// height of lowres frame in pixel lines
        int    leadingBframes;// number of leading B frames for P or I
    
        bool   bScenecut;// Set to false if the frame cannot possibly be part of a real scenecut.
        bool   bKeyframe;
        bool   bLastMiniGopBFrame;
    
        /* lookahead output data */
        int64_t   costEst[X265_BFRAME_MAX +2][X265_BFRAME_MAX +2];
        int64_t   costEstAq[X265_BFRAME_MAX +2][X265_BFRAME_MAX +2];
        int32_t*  rowSatds[X265_BFRAME_MAX +2][X265_BFRAME_MAX +2];
        int       intraMbs[X265_BFRAME_MAX +2];
        int32_t*  intraCost;
        uint8_t*  intraMode;
        int64_t   satdCost;
        uint16_t* lowresCostForRc;
        uint16_t(*lowresCosts[X265_BFRAME_MAX +2][X265_BFRAME_MAX +2]);
        int32_t*  lowresMvCosts[2][X265_BFRAME_MAX +1];
        MV*       lowresMvs[2][X265_BFRAME_MAX +1];
        uint32_t  maxBlocksInRow;
        uint32_t  maxBlocksInCol;
    
        /* used for vbvLookahead */
        int       plannedType[X265_LOOKAHEAD_MAX +1];
        int64_t   plannedSatd[X265_LOOKAHEAD_MAX +1];
        int       indB;
        int       bframes;
    
        /* rate control / adaptive quant data */
        double*   qpAqOffset;// AQ QP offset values for each 16x16 CU
        double*   qpCuTreeOffset;// cuTree QP offset values for each 16x16 CU
        int*      invQscaleFactor;// qScale values for qp Aq Offsets
        uint32_t* blockVariance;
        uint64_t  wp_ssd[3];// This is different than SSDY, this is sum(pixel^2) - sum(pixel)^2 for entire frame
        uint64_t  wp_sum[3];
        uint64_t  frameVariance;
    
        /* cutree intermediate data */
        uint16_t* propagateCost;
        double    weightedCostDelta[X265_BFRAME_MAX +2];
        ReferencePlanes weightedRef[X265_BFRAME_MAX +2];
    
        bool create(PicYuv*origPic,int _bframes,bool bAqEnabled);
        void destroy();
        void init(PicYuv*origPic,int poc);
    };
    }
    

    Does anybody knows why?Any clue would be appreciated!Thanks in advance!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I notice that MotionReference is defined in the X265_NS namespace, whereas your error message refers to x265::MotionReference. Could it be that in the given context, the X265_NS namespace was not aliased as x265?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jun 2016
    Posts
    2

    It's not this file that cause the problem

    Quote Originally Posted by laserlight View Post
    I notice that MotionReference is defined in the X265_NS namespace, whereas your error message refers to x265::MotionReference. Could it be that in the given context, the X265_NS namespace was not aliased as x265?
    It's not this file that cause the problem,but another file...
    There is another file 'sllice.h' use the forward declaration as:
    Code:
    #ifndef X265_SLICE_H
    #define X265_SLICE_H
    
    
    #include "common.h"
    
    
    namespace X265_NS {
    // private namespace
    
    
    class Frame;
    class PicList;
    class PicYuv;
    class MotionReference;
    
    
    enum SliceType
    {
        B_SLICE,
        P_SLICE,
        I_SLICE
    };
    
    
    struct RPS
    {
        int  numberOfPictures;
        int  numberOfNegativePictures;
        int  numberOfPositivePictures;
    
    
        int  poc[MAX_NUM_REF_PICS];
        int  deltaPOC[MAX_NUM_REF_PICS];
        bool bUsed[MAX_NUM_REF_PICS];
    
    
        RPS()
            : numberOfPictures(0)
            , numberOfNegativePictures(0)
            , numberOfPositivePictures(0)
        {
            memset(deltaPOC, 0, sizeof(deltaPOC));
            memset(poc, 0, sizeof(poc));
            memset(bUsed, 0, sizeof(bUsed));
        }
    
    
        void sortDeltaPOC();
    };
    
    
    namespace Profile {
        enum Name
        {
            NONE = 0,
            MAIN = 1,
            MAIN10 = 2,
            MAINSTILLPICTURE = 3,
            MAINREXT = 4,
            HIGHTHROUGHPUTREXT = 5
        };
    }
    
    
    namespace Level {
        enum Tier
        {
            MAIN = 0,
            HIGH = 1,
        };
    
    
        enum Name
        {
            NONE = 0,
            LEVEL1 = 30,
            LEVEL2 = 60,
            LEVEL2_1 = 63,
            LEVEL3 = 90,
            LEVEL3_1 = 93,
            LEVEL4 = 120,
            LEVEL4_1 = 123,
            LEVEL5 = 150,
            LEVEL5_1 = 153,
            LEVEL5_2 = 156,
            LEVEL6 = 180,
            LEVEL6_1 = 183,
            LEVEL6_2 = 186,
            LEVEL8_5 = 255,
        };
    }
    
    
    struct ProfileTierLevel
    {
        int      profileIdc;
        int      levelIdc;
        uint32_t minCrForLevel;
        uint32_t maxLumaSrForLevel;
        uint32_t bitDepthConstraint;
        int      chromaFormatConstraint;
        bool     tierFlag;
        bool     progressiveSourceFlag;
        bool     interlacedSourceFlag;
        bool     nonPackedConstraintFlag;
        bool     frameOnlyConstraintFlag;
        bool     profileCompatibilityFlag[32];
        bool     intraConstraintFlag;
        bool     onePictureOnlyConstraintFlag;
        bool     lowerBitRateConstraintFlag;
    };
    
    
    struct HRDInfo
    {
        uint32_t bitRateScale;
        uint32_t cpbSizeScale;
        uint32_t initialCpbRemovalDelayLength;
        uint32_t cpbRemovalDelayLength;
        uint32_t dpbOutputDelayLength;
        uint32_t bitRateValue;
        uint32_t cpbSizeValue;
        bool     cbrFlag;
    
    
        HRDInfo()
            : bitRateScale(0)
            , cpbSizeScale(0)
            , initialCpbRemovalDelayLength(1)
            , cpbRemovalDelayLength(1)
            , dpbOutputDelayLength(1)
            , cbrFlag(false)
        {
        }
    };
    
    
    struct TimingInfo
    {
        uint32_t numUnitsInTick;
        uint32_t timeScale;
    };
    
    
    struct VPS
    {
        HRDInfo          hrdParameters;
        ProfileTierLevel ptl;
        uint32_t         maxTempSubLayers;
        uint32_t         numReorderPics;
        uint32_t         maxDecPicBuffering;
        uint32_t         maxLatencyIncrease;
    };
    
    
    struct Window
    {
        int  leftOffset;
        int  rightOffset;
        int  topOffset;
        int  bottomOffset;
        bool bEnabled;
    
    
        Window()
        {
            bEnabled = false;
        }
    };
    
    
    struct VUI
    {
        int        aspectRatioIdc;
        int        sarWidth;
        int        sarHeight;
        int        videoFormat;
        int        colourPrimaries;
        int        transferCharacteristics;
        int        matrixCoefficients;
        int        chromaSampleLocTypeTopField;
        int        chromaSampleLocTypeBottomField;
    
    
        bool       aspectRatioInfoPresentFlag;
        bool       overscanInfoPresentFlag;
        bool       overscanAppropriateFlag;
        bool       videoSignalTypePresentFlag;
        bool       videoFullRangeFlag;
        bool       colourDescriptionPresentFlag;
        bool       chromaLocInfoPresentFlag;
        bool       frameFieldInfoPresentFlag;
        bool       fieldSeqFlag;
        bool       hrdParametersPresentFlag;
    
    
        HRDInfo    hrdParameters;
        Window     defaultDisplayWindow;
        TimingInfo timingInfo;
    };
    
    
    struct SPS
    {
        /* cached PicYuv offset arrays, shared by all instances of
         * PicYuv created by this encoder */
        intptr_t* cuOffsetY;
        intptr_t* cuOffsetC;
        intptr_t* buOffsetY;
        intptr_t* buOffsetC;
    
    
        int      chromaFormatIdc;        // use param
        uint32_t picWidthInLumaSamples;  // use param
        uint32_t picHeightInLumaSamples; // use param
    
    
        uint32_t numCuInWidth;
        uint32_t numCuInHeight;
        uint32_t numCUsInFrame;
        uint32_t numPartitions;
        uint32_t numPartInCUSize;
    
    
        int      log2MinCodingBlockSize;
        int      log2DiffMaxMinCodingBlockSize;
    
    
        uint32_t quadtreeTULog2MaxSize;
        uint32_t quadtreeTULog2MinSize;
    
    
        uint32_t quadtreeTUMaxDepthInter; // use param
        uint32_t quadtreeTUMaxDepthIntra; // use param
    
    
        uint32_t maxAMPDepth;
    
    
        uint32_t maxTempSubLayers;   // max number of Temporal Sub layers
        uint32_t maxDecPicBuffering; // these are dups of VPS values
        uint32_t maxLatencyIncrease;
        int      numReorderPics;
    
    
        bool     bUseSAO; // use param
        bool     bUseAMP; // use param
        bool     bUseStrongIntraSmoothing; // use param
        bool     bTemporalMVPEnabled;
    
    
        Window   conformanceWindow;
        VUI      vuiParameters;
    
    
        SPS()
        {
            memset(this, 0, sizeof(*this));
        }
    
    
        ~SPS()
        {
            X265_FREE(cuOffsetY);
            X265_FREE(cuOffsetC);
            X265_FREE(buOffsetY);
            X265_FREE(buOffsetC);
        }
    };
    
    
    struct PPS
    {
        uint32_t maxCuDQPDepth;
    
    
        int      chromaQpOffset[2];      // use param
        int      deblockingFilterBetaOffsetDiv2;
        int      deblockingFilterTcOffsetDiv2;
    
    
        bool     bUseWeightPred;         // use param
        bool     bUseWeightedBiPred;     // use param
        bool     bUseDQP;
        bool     bConstrainedIntraPred;  // use param
    
    
        bool     bTransquantBypassEnabled;  // Indicates presence of cu_transquant_bypass_flag in CUs.
        bool     bTransformSkipEnabled;     // use param
        bool     bEntropyCodingSyncEnabled; // use param
        bool     bSignHideEnabled;          // use param
    
    
        bool     bDeblockingFilterControlPresent;
        bool     bPicDisableDeblockingFilter;
    };
    
    
    struct WeightParam
    {
        // Explicit weighted prediction parameters parsed in slice header,
        uint32_t log2WeightDenom;
        int      inputWeight;
        int      inputOffset;
        bool     bPresentFlag;
    
    
        /* makes a non-h265 weight (i.e. fix7), into an h265 weight */
        void setFromWeightAndOffset(int w, int o, int denom, bool bNormalize)
        {
            inputOffset = o;
            log2WeightDenom = denom;
            inputWeight = w;
            while (bNormalize && log2WeightDenom > 0 && (inputWeight > 127))
            {
                log2WeightDenom--;
                inputWeight >>= 1;
            }
    
    
            inputWeight = X265_MIN(inputWeight, 127);
        }
    };
    
    
    #define SET_WEIGHT(w, b, s, d, o) \
        { \
            (w).inputWeight = (s); \
            (w).log2WeightDenom = (d); \
            (w).inputOffset = (o); \
            (w).bPresentFlag = (b); \
        }
    
    
    class Slice
    {
    public:
    
    
        const SPS*  m_sps;
        const PPS*  m_pps;
        Frame*      m_refFrameList[2][MAX_NUM_REF + 1];
        PicYuv*     m_refReconPicList[2][MAX_NUM_REF + 1];
    
    
        WeightParam m_weightPredTable[2][MAX_NUM_REF][3]; // 
    [list][refIdx][0:Y, 1:U, 2:V]
        MotionReference (*m_mref)[MAX_NUM_REF + 1];
        RPS         m_rps;
    
    
        NalUnitType m_nalUnitType;
        SliceType   m_sliceType;
        int         m_sliceQp;
        int         m_poc;
        int         m_lastIDR;
    
    
        uint32_t    m_colRefIdx;       // never modified
    
    
        int         m_numRefIdx[2];
        int         m_refPOCList[2][MAX_NUM_REF + 1];
    
    
        uint32_t    m_maxNumMergeCand; // use param
        uint32_t    m_endCUAddr;
    
    
        bool        m_bCheckLDC;       // TODO: is this necessary?
        bool        m_sLFaseFlag;      // loop filter boundary flag
        bool        m_colFromL0Flag;   // collocated picture from List0 or List1 flag
    
    
        Slice()
        {
            m_lastIDR = 0;
            m_sLFaseFlag = true;
            m_numRefIdx[0] = m_numRefIdx[1] = 0;
            memset(m_refFrameList, 0, sizeof(m_refFrameList));
            memset(m_refReconPicList, 0, sizeof(m_refReconPicList));
            memset(m_refPOCList, 0, sizeof(m_refPOCList));
            disableWeights();
        }
    
    
        void disableWeights();
    
    
        void setRefPicList(PicList& picList);
    
    
        bool getRapPicFlag() const
        {
            return m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL
                || m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA;
        }
    
    
        bool getIdrPicFlag() const
        {
            return m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL;
        }
    
    
        bool isIRAP() const   { return m_nalUnitType >= 16 && m_nalUnitType <= 23; }
    
    
        bool isIntra()  const { return m_sliceType == I_SLICE; }
    
    
        bool isInterB() const { return m_sliceType == B_SLICE; }
    
    
        bool isInterP() const { return m_sliceType == P_SLICE; }
    
    
        uint32_t realEndAddress(uint32_t endCUAddr) const;
    };
    
    
    }
    
    
    #endif // ifndef X265_SLICE_H
    If I change forward declaration to including corresponding header, there will be no error!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by stevenHu
    If I change forward declaration to including corresponding header, there will be no error!
    Then perhaps you need the definition, not merely a forward declaration, in that context, so I don't see what is the problem. If you think otherwise, then you need to be more specific as to what is the exact error message and where is it detected, etc. I'm not going to wade through the code when you error message mentions a x265 namespace (or class) that appears nowhere in the code that you have shown.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    There's also a crap ton of code posted as well. I don't know about you guys but if anyone posts anything over 150 lines without an explicit request, I kind of just stop reading.

  6. #6
    Banned
    Join Date
    Oct 2014
    Location
    Home
    Posts
    135
    Quote Originally Posted by MutantJohn View Post
    There's also a crap ton of code posted as well. I don't know about you guys but if anyone posts anything over 150 lines without an explicit request, I kind of just stop reading.
    I like learning.

  7. #7
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by Tien Nguyen View Post
    I like learning.
    I do too. Doesn't mean that wading through someone's code out of context is all that useful or even critical to getting them help.

    I think Laserlight's signature is pretty solid advice. Post the smallest amount of code that duplicates the issue.

  8. #8
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I do too.
    O_o

    Are you sure?

    I note that you still haven't answered those questions of mine despite having the repeating the same basic issue at least once.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  9. #9
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by phantomotap View Post
    O_o

    Are you sure?

    I note that you still haven't answered those questions of mine despite having the repeating the same basic issue at least once.

    Soma
    I kind of know what you're alluding to but you'll have to refresh my memory as I'm not sure exactly what you're talking about.

    Edit:

    I think this is about that time I was asking for help creating one of my very first C++ containers. I can't remember exactly what you were talking about though. I just remember that in retrospect, it was very stupid container design and I was better off just coding an unrolled linked list. Learning how to write a container though helped my C++ tremendously.
    Last edited by MutantJohn; 07-01-2016 at 03:37 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. forward declaration error
    By beebee in forum C Programming
    Replies: 7
    Last Post: 11-25-2012, 05:35 PM
  2. forward declaration error?
    By sugarfree in forum C++ Programming
    Replies: 3
    Last Post: 04-25-2010, 12:11 AM
  3. Forward declaration with g++
    By blakaxe in forum C++ Programming
    Replies: 4
    Last Post: 06-17-2009, 11:44 AM
  4. Forward declaration with g++
    By blakaxe in forum Linux Programming
    Replies: 0
    Last Post: 06-15-2009, 09:22 AM
  5. forward declaration
    By l2u in forum C++ Programming
    Replies: 6
    Last Post: 07-18-2007, 02:09 PM

Tags for this Thread