diff --git a/src/arduino.cc/builder/ctags/ctags_to_prototypes.go b/src/arduino.cc/builder/ctags/ctags_to_prototypes.go index 459174d8..d4138416 100644 --- a/src/arduino.cc/builder/ctags/ctags_to_prototypes.go +++ b/src/arduino.cc/builder/ctags/ctags_to_prototypes.go @@ -56,32 +56,32 @@ func (p *CTagsParser) findLineWhereToInsertPrototypes() int { } func (p *CTagsParser) firstFunctionPointerUsedAsArgument() int { - functionNames := p.collectFunctionNames() + functionTags := p.collectFunctions() for _, tag := range p.tags { - if functionNameUsedAsFunctionPointerIn(tag, functionNames) { + if functionNameUsedAsFunctionPointerIn(tag, functionTags) { return tag.Line } } return -1 } -func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionNames []string) bool { - for _, functionName := range functionNames { - if strings.Index(tag.Code, "&"+functionName) != -1 { +func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionTags []*types.CTag) bool { + for _, functionTag := range functionTags { + if tag.Line != functionTag.Line && strings.Index(tag.Code, "&"+functionTag.FunctionName) != -1 { return true } } return false } -func (p *CTagsParser) collectFunctionNames() []string { - names := []string{} +func (p *CTagsParser) collectFunctions() []*types.CTag { + functionTags := []*types.CTag{} for _, tag := range p.tags { if tag.Kind == KIND_FUNCTION { - names = append(names, tag.FunctionName) + functionTags = append(functionTags, tag) } } - return names + return functionTags } func (p *CTagsParser) firstFunctionAtLine() int { diff --git a/src/arduino.cc/builder/test/sketch_with_fake_function_pointer/sketch_with_fake_function_pointer.ino b/src/arduino.cc/builder/test/sketch_with_fake_function_pointer/sketch_with_fake_function_pointer.ino new file mode 100644 index 00000000..eb83500c --- /dev/null +++ b/src/arduino.cc/builder/test/sketch_with_fake_function_pointer/sketch_with_fake_function_pointer.ino @@ -0,0 +1,19 @@ +template< uint16_t nBuffSize > + class Foo{ + public: + + template< uint16_t N > + Foo &operator +=( const Foo &ref ){ + //... + return *this; + } +}; + +Foo<64> a; +Foo<32> b; + +void setup(){ + a += b; +} + +void loop(){} diff --git a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go index 5cbbf5cf..160c81c5 100644 --- a/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go +++ b/src/arduino.cc/builder/test/try_build_of_problematic_sketch_test.go @@ -205,6 +205,10 @@ func TestTryBuild039(t *testing.T) { tryBuildWithContext(t, ctx, "sketch12", "sketch12.ino") } +func TestTryBuild040(t *testing.T) { + tryBuild(t, "sketch_with_fake_function_pointer", "sketch_with_fake_function_pointer.ino") +} + func makeDefaultContext(t *testing.T) *types.Context { DownloadCoresAndToolsAndLibraries(t)