0

I am trying to compile QT5.3
The files in question are qv4executableallocator_p.h and qv4executableallocator.cpp. Relevant code snippet from the header is below

 struct Allocation{
    Allocation()
    : addr(0)
    , size(0)
    , free(true)
    , next(0)
    , prev(0)
    {}
    void *start() const;
    void invalidate() { addr = 0; }
    bool isValid() const { return addr != 0; }
    void deallocate(ExecutableAllocator *allocator);
    private:
        ~Allocation() {}
        friend class ExecutableAllocator;
        Allocation *split(size_t dividingSize);
        bool mergeNext(ExecutableAllocator *allocator);
        bool mergePrevious(ExecutableAllocator *allocator);
        quintptr addr;
        uint size : 31; // More than 2GB of function code? nah :)
        uint free : 1;
        Allocation *next;
        Allocation *prev;
};  

In the cpp function ExecutableAllocator::ChunkOfPages::~ChunkOfPages() I get a compilation error when trying to access alloc->next.

QV4::ExecutableAllocator::Allocation* QV4::ExecutableAllocator::Allocation::next’ is private

Code can be seen online at https://qt.gitorious.org/qt/qtdeclarative/source/be6c91acc3ee5ebb8336b9e79df195662ac11788:src/qml/jsruntime

My gcc version is relatively old... 4.1
Is this the issue or is something else wrong in my environment. I would like a way to go forward. I am stuck with this compiler, since it is the one I have to use on my target platform

MrTambourineMan
  • 1,025
  • 1
  • 11
  • 19
bobby
  • 2,629
  • 5
  • 30
  • 56
  • as it says, next is private. This makes it only accessible by the class-instance itself. – Sebastian Lange Nov 27 '14 at 09:16
  • 1
    Please use at least gcc 4.6. Even if you get through this, unfortunately you will very likely have other issues. Why are you stuck with a nearly 9 years old compiler version?? – László Papp Nov 27 '14 at 09:46
  • @lpapp The platform I am working is old, and there is no support for an updated toolchain or for that matter kernel from the vendor. Assuming I am stuck with this, is the reason this doesnt work, what martin answered below? – bobby Nov 27 '14 at 09:54
  • Which vendor is this? I know that TI is almost all the time far behind, but even they offer at least 4.3, and this is 4.1. I would not really go down this road. Like I said, you will solve this, but there will be other - like several at least - patches to carry on with your own distribution. It will get pretty complex. – László Papp Nov 27 '14 at 10:24
  • Its an existing product line, to which QT support is being added. Problem is there is nobody willing to support (Pay?) for validating an upgraded kernel and and toolchain – bobby Nov 27 '14 at 12:09

1 Answers1

1

I'd guess that the QV4::ExecutableAllocator::ChunkOfPages struct is not directly befriended with Allocation, so you can't access Allocation's private data in its destructor in C++ prior to C++11 standard.

Try adding friend struct ExecutableAllocator::ChunkOfPages to the Allocation definition, that should do the trick.

There was a slight change in the way nested classes are handled in C++11 (cited from cppreference.com):

Prior C++11, member declarations and definitions inside the nested class of the friend of class T cannot access the private and protected members of class T, but some compilers accept it even in pre-C++11 mode.

Which could explain why this worked in a new compiler, but not in your old one.

Martin Prazak
  • 1,476
  • 12
  • 20
  • This worked. However this is standard QT code, so I dont know why this change is needed. ChunkOfPages and Allocation are both structures defined in the class ExecutableAllocator. Is there some gcc dependancy here? – bobby Nov 27 '14 at 09:26
  • No, don't think so - even though both of these structs are defined in the same class, they are still separate structs and have to be befriended to each other if they need to access each other's private data. – Martin Prazak Nov 27 '14 at 09:28
  • Actually, [this](http://en.cppreference.com/w/cpp/language/friend) says that there was a slight change in how private data are handled in nested classes in C++11, so that would explain why it is in the new code, but doesn't compile with your old compiler. I'll amend my answer to add this. – Martin Prazak Nov 27 '14 at 09:40
  • Amended, even though I might be misinterpreting that statement utterly, because it does not exactly reflect your code. – Martin Prazak Nov 27 '14 at 09:45