C++ Builder E2303 Type name expected - c++builder

I am attempting to use the HP APDK with C++ Builder in RAD Studio XE5. I need to derive a class PlatformServices (or any name of my choosing) from HP's base class SystemServices. Here is my header PlatformServices.h:
/***************************************************************************\
APDK Platform Services
\***************************************************************************/
#ifndef _H_PLATFORMSERVICES
#define _H_PLATFORMSERVICES
#include "header.h" // HP APDK General Header
// class SystemServices {
// };
class PlatformServices : public SystemServices {
~PlatformServices ();
PlatformServices ();
};
#endif
Compiled as-is, I get the error:
[bcc32 Error] PlatformServices.h(13): E2303 Type name expected
Full parser context
PlatformServices.cpp(5): #include PlatformServices.h
PlatformServices.h(13): class PlatformServices
But if I comment out the #include and uncomment the definition for an empty class named SystemServices, the code compiles without error.
I can preprocess the code as-is (in Project Manager, right click on PlatformServices and select Preprocess) and I can see that the #include defines a well formed SystemServices class.
I've also disabled pre-compiled headers.
This seems like a compiler error, but it's a poor workman who blames his tools. I just can't believe C++ Builder would choke on something this basic, yet I can't see what I'm doing wrong. Help!
P.S. I've posted the full code and project files at: https://www.dropbox.com/s/sn1377y59r3idtz/apdk.zip

SystemServices is declared in the apdk namespace, so you need to specify that in your code, either directly:
class PlatformServices : public apdk::SystemServices
Or with a using namespace statement:
using namespace apdk;
class PlatformServices : public SystemServices

Related

Unresolved external linker error in C++Builder

I am new to C++ Builder. I am translating a Delphi project into C++. I have translated some of the Delphi code into C++ and it compiles fine in C++Builder, but I get an error:
Unresolved external ColorClasses::TColorList:: referenced from ...
when I use the TColorList constructor in my MainForm in this way:
ColorClasses::TColorList *cl;
cl = new ColorClasses::TColorList();
The TColorList constructor is defined as follows in file ColorClasses.cpp:
__fastcall ColorClasses::TColorList::TColorList() : TColorClass()
{
fcolor_list = new TList();
}
The TColorList class is declared as follows in file ColorClasses.h:
class DELPHICLASS TColorList;
class PASCALIMPLEMENTATION TColorList : public TColorClass
{
private:
TList* fcolor_list;
public:
__fastcall TColorList();
virtual __fastcall ~TColorList();
};
I have searched the StackOverflow site for similar questions relevant to C++Builder, but I can't find one specific to my problem.
The problem seems to resolve itself if I remove the keywords DELPHICLASS and PASCALIMPLEMENTATION.

Can I use Googlemock mock objects in unit tests with C++Builder?

Googlemock can help build mock classes with which it is possible to detect if one method calls another method and with what parameters, and influence the behaviour of the called method.
E.g., to test that method a() in class UnderTest actually calls method b()
class UnderTest {
public:
/// Method a() calls method b().
virtual void a() {b();}
/// Method b() does nothing.
virtual void b() {}
};
one can write a mock class which overwrites method b()
class UnderTestMock : public UnderTest {
public:
MOCK_METHOD0(b, void());
};
and test if the method b() is actually called after calling method a():
TEST(UnderTest, aCallsB) {
UnderTestMock mock;
EXPECT_CALL(mock, b());
mock.a();
}
Can I use Googlemock like this with C++Builder 11.2?
No, at the moment it is not possible to use Googlemock like this with C++Builder 11.2.
The Googletest project (which includes Googlemock) itself has removed all support for C++Builder in 2019. Embarcadero has since published their own patched version of Googletest in a GetIt package, which includes project files to build Googletest and Googlemock and some usage examples.
The Googlemock-related project files are all somewhat broken, e.g. the gmock.cbproj file inserts a source file into the gmock.a library that performs some unrelated tests on Googletest. These project file errors can all be fixed easily by removing source files from the projects that do not belong there and rebuild.
However, after fixing the gmock.cbproj project file, it turns out that the main feature of Googlemock, the EXPECT_CALL() macro, is not supported by C++Builder 11.2:
This is a simple source file which puts the code pieces from the question together, adds a main function and the required includes:
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <tchar.h>
int _tmain(int argc, _TCHAR* argv[])
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
class UnderTest {
public:
/// Method a() calls method b().
virtual void a() {b();}
/// Method b() does nothing.
virtual void b() {}
};
class UnderTestMock : public UnderTest {
public:
MOCK_METHOD0(b, void());
};
TEST(UnderTest, aCallsB) {
UnderTestMock mock;
EXPECT_CALL(mock, b());
mock.a();
}
This sample works fine with Googlemock with other compilers (at most, tchar, _tmain need to be replaced with char, main), however, with C++Builder, some required features are missing from either the compiler or from the C++ standard library. The error message when compiling with C++Builder's clang-based 64-bit compiler is
Build FAILED.
C:\Users\...\Documents\Embarcadero\Studio\22.0\CatalogRepository\GoogleTest-2021.09\googlemock\include\gmock/gmock-nice-strict.h(134,6): C++ warning : __declspec attribute 'empty_bases' is not supported
C:\Users\...\Documents\Embarcadero\Studio\22.0\CatalogRepository\GoogleTest-2021.09\googlemock\include\gmock/gmock-nice-strict.h(174,6): C++ warning : __declspec attribute 'empty_bases' is not supported
C:\Users\...\Documents\Embarcadero\Studio\22.0\CatalogRepository\GoogleTest-2021.09\googlemock\include\gmock/gmock-nice-strict.h(215,6): C++ warning : __declspec attribute 'empty_bases' is not supported
c:\program files (x86)\embarcadero\studio\22.0\include\dinkumware64\type_traits(2686,1): C++ error : no matching function for call to 'invoke'
c:\program files (x86)\embarcadero\studio\22.0\include\dinkumware64\functional(216,10): C++ error : > in instantiation of function template specialization 'std::_Invoke_ret<void, testing::internal::DoDefaultAction &>' requested here
c:\program files (x86)\embarcadero\studio\22.0\include\dinkumware64\functional(165,2): C++ error : > in instantiation of member function 'std::_Func_impl<testing::internal::DoDefaultAction, std::allocator<int>, void>::_Do_call' requested here
c:\program files (x86)\embarcadero\studio\22.0\include\dinkumware64\xmemory0(704,23): C++ error : > in instantiation of function template specialization 'std::_Func_impl<testing::internal::DoDefaultAction, std::allocator<int>, void>::_Func_impl<testing::internal::DoDefaultAction, const std::allocator<int> &>' requested here
c:\program files (x86)\embarcadero\studio\22.0\include\dinkumware64\xmemory0(845,6): C++ error : > in instantiation of function template specialization 'std::allocator<std::_Func_impl<testing::internal::DoDefaultAction, std::allocator<int>, void> >::construct<std::_Func_impl<testing::internal::DoDefaultAction, std::allocator<int>, void>, testing::internal::DoDefaultAction, const std::allocator<int> &>' requested here
c:\program files (x86)\embarcadero\studio\22.0\include\dinkumware64\xmemory0(994,13): C++ error : > in instantiation of function template specialization 'std::allocator_traits<std::allocator<std::_Func_impl<testing::internal::DoDefaultAction, std::allocator<int>, void> > >::construct<std::_Func_impl<testing::internal::DoDefaultAction, std::allocator<int>, void>, testing::internal::DoDefaultAction, const std::allocator<int> &>' requested here
c:\program files (x86)\embarcadero\studio\22.0\include\dinkumware64\functional(376,6): C++ error : > (skipping 6 contexts in backtrace; use -ftemplate-backtrace-limit=0 to see all)
C:\Users\...\Documents\Embarcadero\Studio\22.0\CatalogRepository\GoogleTest-2021.09\googlemock\include\gmock/gmock-actions.h(470,4): C++ error : > in instantiation of function template specialization 'testing::Action<void ()>::Init<testing::internal::DoDefaultAction>' requested here
C:\Users\...\Documents\Embarcadero\Studio\22.0\CatalogRepository\GoogleTest-2021.09\googlemock\include\gmock/gmock-spec-builders.h(909,8): C++ error : > in instantiation of function template specialization 'testing::Action<void ()>::Action<testing::internal::DoDefaultAction, void>' requested here
C:\Users\...\Documents\Embarcadero\Studio\22.0\CatalogRepository\GoogleTest-2021.09\googlemock\include\gmock/gmock-spec-builders.h(1629,12): C++ error : > in instantiation of member function 'testing::internal::TypedExpectation<void ()>::TypedExpectation' requested here
C:\Users\...\Documents\Embarcadero\Studio\22.0\CatalogRepository\GoogleTest-2021.09\googlemock\include\gmock/gmock-spec-builders.h(1284,29): C++ error : > in instantiation of member function 'testing::internal::FunctionMocker<void ()>::AddNewExpectation' requested here
C:\Users\...\Documents\Embarcadero\Studio\Projects\gmocktest\main.cpp(26,2): C++ error : > in instantiation of member function 'testing::internal::MockSpec<void ()>::InternalExpectedAt' requested here
c:\program files (x86)\embarcadero\studio\22.0\include\dinkumware64\type_traits(2664,6): C++ error : > candidate template ignored: substitution failure [with _Callable = testing::internal::DoDefaultAction &, _Types = <>]: no matching function for call to '_Call'
3 Warning(s)
13 Error(s)
The two example projects included in the GetIt package for Googlemock hint that some isolated aspects of Googlemock may be working, like at least one Googlemock matcher works inside the EXPECT_THAT() macro, but none of the examples compiled by the GetIt package make use of the main feature of Googlemock, the EXPECT_CALL() macro.

Why are my custom clang-tidy checks not showing up after adding custom module?

I have a few custom clang-tidy checks. For instance one in the cppcoreguidelines module and another in the misc module. They work fine. Now I extended clang-tidy by a custom module to organize them into.
When I rebuild, it succeeds but when I run ./clang-tidy -list-checks -checks=*, my checks do not show up.
Here is what I did to add my custom module called sw:
Created a subdirectory sw under /clang-tools-extra/clang-tidy/
Updated /clang-tools-extra/clang-tidy/CMakeLists.txt by:
adding add_subdirectory(sw) right below add_subdirectory(readability)
listing clangTidySWModule inside the set(ALL_CLANG_TIDY_CHECKS ...) command
Added /clang-tools-extra/clang-tidy/sw/CMakeLists.txt with the following content:
set(LLVM_LINK_COMPONENTS
FrontendOpenMP
Support
)
add_clang_library(clangTidySWModule
AllCapsEnumeratorsCheck.cpp
CatchByConstReferenceCheck.cpp
SWTidyModule.cpp
LINK_LIBS
clangTidy
clangTidyUtils
DEPENDS
omp_gen
)
clang_target_link_libraries(clangTidySWModule
PRIVATE
clangAnalysis
clangAST
clangASTMatchers
clangBasic
clangLex
clangTooling
)
Added /clang-tools-extra/clang-tidy/sw/SWTidyModule.cpp with the following content:
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "AllCapsEnumeratorsCheck.h"
#include "CatchByConstReferenceCheck.h"
namespace clang {
namespace tidy {
namespace sw {
class SWModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<AllCapsEnumeratorsCheck>(
"sw-all-caps-enumerators");
CheckFactories.registerCheck<CatchByConstReferenceCheck>(
"sw-catch-by-const-reference");
}
};
// Register the SWModule using this statically initialized variable.
static ClangTidyModuleRegistry::Add<SWModule>
X("sw-module", "Adds my custom checks.");
} // namespace sw
// This anchor is used to force the linker to link in the generated object file
// and thus register the ReadabilityModule.
volatile int SWModuleAnchorSource = 0;
} // namespace tidy
} // namespace clang
I added the two checks all-caps-enumerators and catch-by-const-reference like I did under other modules before:
python3 add_new_check.py sw all-caps-enumerators
python3 add_new_check.py sw catch-by-const-reference
Am I missing something? Why are my checks not showing up?
I found what I was missing here. Hopefully this post will at least help others finding an answer quicker plus where to exactly add the missing piece.
I was missing the following in /clang-tools-extra/clang-tidy/ClangTidyForceLinker.h:
// This anchor is used to force the linker to link the SWModule.
extern volatile int SWModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED SWModuleAnchorDestination =
SWModuleAnchorSource;
Now my checks show up and I am happy (:

How to get my own ICultureSelector implementation injected in the framework

I have implemented my version of ICultureSelector, in a custom module.
Here it is a part of its definition (my question is not about the logic to select the culture; I tried with my own namespace and also with a namespace same as the namespace used in the module Orchard.Localization):
namespace Orchard.Localization.Selectors
{
[OrchardFeature("Orchard.Localization.CultureSelector")]
public class ShortRouteCultureSelector : ICultureSelector
{
public CultureSelectorResult GetCulture(HttpContextBase context)
{
...
I put a breakpoint in the method GetCurrentCulture of the class CurrentCultureWorkContext in the Orchard.Framework project, and I see that the variable IEnumerable _cultureSelectors contains all the implementation of ICultureSelector of the module Orchard.Localization but not my implementation, that is never used.
What am I missing?
Remove the OrchardFeature attribute or define your own feature name as Orchard.Localization.CultureSelector is defined in Orchard.Localization module already.

Monodroid Spinner Resource reference error

I'm following the spinner from monodroid tutorial. But encountered problem on the resource.
It cannot lookup the SimpleSpinnerItem & SimpleSpinnerDropDownItem on VS 2010.
Am I missing something?
Edit: Create a partial class to register android runtime as per jonp
public partial class Resource
{
public partial class Layout
{
[Register("simple_spinner_dropdown_item")]
public const int SimpleSpinnerDropDownItem = 17367049;
[Register("simple_spinner_item")]
public const int SimpleSpinnerItem = 17367048;
}
}
Edit 2: Tried the global resource
Edit 3: Conflict on my project namespace
I already identified why the const cannot be recognize. It's because of my namespace projectname.Android, it's being duplicated. When I changed it to projectname.AndroidMobile the global resource is there.
See the conflict below.
Also, to avoid the conflict just use the global:: as per jonp
You need to qualify the class, as there are two Resource types: one local to your project (Your.Namespace.Resource, located in Resource.designer.cs), and global::Android.Resource. You need to use global::Android.Resource.Layout.SimpleSpinnerItem.

Resources