1

I am trying to compile FBreader libraries to use with my project. Two of the .so libraries are being compiled successfully but on the last library it is giving me the following error

jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp:42:31: error: default initialization of an object of const type 'const XHTMLTagInfoList' without a
      user-provided default constructor
static const XHTMLTagInfoList EMPTY_INFO_LIST;
                              ^

After looking at the c++ code following is the line where the error is occuring

static const XHTMLTagInfoList EMPTY_INFO_LIST;

And the XHTMLTagInfoList var is

const XHTMLTagInfoList &XHTMLReader::tagInfos(size_t depth) const {
        if (myTagDataStack.size() < depth + 2) {
                return EMPTY_INFO_LIST;
        }
        return myTagDataStack[myTagDataStack.size() - depth - 2]->Children;
}

I am not that good at c++. Please help in resolving the error

After updating to static const XHTMLTagInfoList EMPTY_INFO_LIST{};

Following error is occuring

Error ScreenShot

Sandeep Singh
  • 745
  • 4
  • 20

1 Answers1

0

I'll quote this answer:

The C++ standard (section 8.5) says:

If a program calls for the default initialization of an object of a const-qualified type T, T shall be a class type with a user-provided default constructor.

if we'd go to XHTMLTagInfoList definition we would see that it does not have user defined ctor indeed.

To fix your problem you just need to use empty initializer:

static const XHTMLTagInfoList EMPTY_INFO_LIST{};

Note, that it would not be required for non-const declaration


Edit: Note that you most likely don't have -std=c++11 enabled, that would fix your error

Community
  • 1
  • 1
Oleg Bogdanov
  • 1,712
  • 13
  • 19
  • Thanks, I will try it in the morning and will let you know if it works. I hope it works. – Sandeep Singh Dec 15 '16 at 18:41
  • I have added `{}` after `EMPTY_INFO_LIST`, but now am getting following error `jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp:42:31: error: default initialization of an object of const type 'const XHTMLTagInfoList' without a user-provided default constructor static const XHTMLTagInfoList EMPTY_INFO_LIST{}; ^ jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp:42:46: error: expected ';' after top level declarator static const XHTMLTagInfoList EMPTY_INFO_LIST{}; ^ ` . Please help. – Sandeep Singh Dec 16 '16 at 05:08
  • Sorry how am I supposed to know which line number is for what? The last error is about semicolon, have you added one? – Oleg Bogdanov Dec 16 '16 at 05:13
  • I have added the screenshot in my question. Currently I have removed const and built it, will it have any adverse effects on the library. I will give it try after adding semicolon. – Sandeep Singh Dec 16 '16 at 05:39
  • Have tried adding semicolon after `EMPTY_INFO_LIST` so the line is now `static const XHTMLTagInfoList EMPTY_INFO_LIST;{};`. Which also is giving error as `error: expected unqualified-id static const XHTMLTagInfoList EMPTY_INFO_LIST;{};` – Sandeep Singh Dec 16 '16 at 05:43
  • No the last line does not make any sense, I thought you could have forgot to add in at the end of the whole line. As for making object non const, it should not make any adverse effect unless you will go and modify object in unexpected (for library) way, because now you cam modify it – Oleg Bogdanov Dec 16 '16 at 05:50
  • So, what should be the way forward? Should I go with having a `non-const` var or is there any other way to overcome it? I have not made any changes the `struct` or it's `class`. – Sandeep Singh Dec 16 '16 at 05:54
  • non-const version wont do any harm. Clang and gcc seem to have different opinions on this issue, Im almost sure you are building with gcc toolchain, change to clang would take this issue away but may bring up other incompatibilities, no point in doing this now – Oleg Bogdanov Dec 16 '16 at 06:00
  • oh i know, you dont have c++11 enabled in your build, that would fix it – Oleg Bogdanov Dec 16 '16 at 06:03
  • Thank you so much for helping. I will now go and build FBreader. Now importing it to Android Studio is also a pain. I have tried importing but most of the Java files are not being copied to the new structure. Will resolve it now. Thank you for your help – Sandeep Singh Dec 16 '16 at 06:03
  • Ok I will explore c++11 option also. And how do I enable it please. – Sandeep Singh Dec 16 '16 at 06:04
  • you add `APP_CPPFLAGS := -std=c++11` line in your Application.mk file. If you think this is enough please accept an answer (or dont if you think it missed the target) – Oleg Bogdanov Dec 16 '16 at 06:06
  • After adding c++11 I am getting multiple errors like this one `jni/NativeFormats/fbreader/src/formats/doc/OleStorage.cpp:62:52: error: constant expression evaluates to 224 which cannot be narrowed to type 'char' [-Wc++11-narrowing] static const char OLE_SIGN[] = {0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, 0}; ` Its asking for explicit casting to silent the error – Sandeep Singh Dec 16 '16 at 06:22
  • Sorry, we can't just go fixing your code line by line, right? I suggest going with non-const solution – Oleg Bogdanov Dec 16 '16 at 06:29
  • Yes. Thanks for your help though. I will accept the answer as it may give pointers to people if they are stuck on the same. Going with non-const solution then. – Sandeep Singh Dec 16 '16 at 06:30