Skip to content

Build now failing when using template class. #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Chris--A opened this issue Jan 20, 2017 · 3 comments · Fixed by #207
Closed

Build now failing when using template class. #206

Chris--A opened this issue Jan 20, 2017 · 3 comments · Fixed by #207
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project

Comments

@Chris--A
Copy link

Using IDE 1.8.2

After doing up some code for a forum user, I did a test compile. When I came back to my PC, flames were shooting out the CD drive, and the bit bucket under my desk was overflowing with nibbles of 1's.

To solve the issue, I now have to manually add setup and loop prototypes.

void setup();
void loop();

template< uint16_t nBuffSize >
  class Foo{
    public: 
  
    template< uint16_t N >
      Foo &operator +=( const Foo<N> &ref ){
        //...
        return *this;
    }
};

Foo<64> a;
Foo<32> b;

void setup(){
  a += b;
}

void loop(){}

The preprocessor adds the setup and loop prototypes in between:
template< uint16_t N > and
Foo &operator +=( const Foo<N> &ref ){
...in the middle of the class.

@facchinm
Copy link
Member

#182 should solve it, I'm testing it immediately

@facchinm
Copy link
Member

unfortunately it doesn't work in this case 🙁
Investigating

facchinm added a commit to facchinm/arduino-builder that referenced this issue Jan 20, 2017
Fixes arduino#206

The sample code from the issue provided a smart way to cheat the dumb FP parser.
In fact, the & is referred to the return type (correct) but the comparator doesn't know about semantics and simply prepends the ampersand before searching for the match.
So the code matches itself, which makes absolutely no sense.
Avoiding this occurrence fixes the issue, however the entire code for prototype line insertion should be refactored in a saner way (see arduino#180 and arduino#191 for another problem)
@facchinm
Copy link
Member

@Chris--A , the "problem" with your code is the return type of operator += or, more precisely, the fact that there is no space between the ampersand and "operator" word. PR #207 should fix this issue in a sane way (but we should really take a look and refactor the line insertion code)

@per1234 per1234 added conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project labels Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: preprocessor Related to sketch preprocessing type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants