Skip to content

generated hpp file is not #included by generated cpp file [BUG] #1145

@GrahamAsher

Description

@GrahamAsher

The current system for creating and using classes outside the main cpp2 file is to write a file with the extension .h2 containing the classes that are needed, then put #include "myheader.h2" at the top of the cpp2 file. The idea is that

  1. cppfront creates two files from the h2 file: a .h file containing declarations, and a .hpp file containing definitions.
  2. cppfront translates #include "myheader.h2" in the cpp2 file into two statements in the generated cpp file: #include "myheader.h" at the top, and ...
  3. #include "myheader.hpp" later on.

Steps 1 and 2 work, but step 3 does not. No #include "myheader.hpp" statement is added by cppfront to the generated cpp file.

Suggested fix (works for me, but I have not analysed the code and the fix may not be correct in all circumstances): move the statement printer.print_extra( hpp_includes ); in to_cpp1.hpp out of its conditional block. Here is a patch:

 source/to_cpp1.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source/to_cpp1.h b/source/to_cpp1.h
index 75880d5..b7f713d 100644
--- a/source/to_cpp1.h
+++ b/source/to_cpp1.h
@@ -1519,9 +1519,9 @@ public:
             printer.print_extra( "\n#ifndef " + cpp1_FILENAME+"_CPP2" );
             printer.print_extra( "\n#define " + cpp1_FILENAME+"_CPP2" + "\n\n" );
 
-            printer.print_extra( hpp_includes );
         }
 
+        printer.print_extra(hpp_includes);
 
         //---------------------------------------------------------------------
         //  Do phase2_func_defs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions